Re: do not truncate long filenames beginning with dot

"Sebastian Geerken" <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
On Sa, Jun 15, 2013, Dennis New wrote:
> On Tue, 11 Jun 2013 23:26:21 -0400, Jorge Arellano Cid wrote:
> > On Tue, Jun 11, 2013 at 09:23:29PM +0200, Johannes Hofmann wrote:
> > > On Mon, Jun 10, 2013 at 07:15:45PM -0400, Jorge Arellano Cid wrote:
> > > > On Mon, Jun 10, 2013 at 10:41:23PM +0200, Johannes Hofmann wrote:
> > > > > On Wed, May 29, 2013 at 04:50:21AM -0400, Dennis New wrote:
> > > > > > Sometimes, when trying to save a document with long
> > > > > > filenames, the truncated default save-as filename will start
> > > > > > with a dot. (Ie. a hidden file.) This behaviour should
> > > > > > change. Perhaps truncate the end of the filename instead (and
> > > > > > preserve the file extension)?
> > > > > 
> > > > > Do you have an example where this happens? I see that it can
> > > > > happen with URLs like http://dillo.org/bla/.blub
> > > > > Is this the case where you are seeing the issue or do you get it
> > > > > with other types of URLs as well?
> > > > 
> > > >   I was to ask the same question days ago (yes I reviewed the
> > > > code to make a quick patch and it cuts starting from the end). An
> > > > example would be clarifying.
> > > 
> > > If we don't get any more feedback, I'd just replace dots with
> > > underscores as well. What do you think?
> > 
> >   That was one of the first things I considered, but thought that
> > when saving a ".config" file it was good to keep the name. I'd like
> > to know the real problem the user had.
> 
> The problem is with very long filenames, such as:
> 
> http://dennisn.dyndns.org/guest/pubstuff/dillo.long.file.name-0.69_r1337.file.123456789012345678901234567890123.txt
> 
> Dillo seems to truncate with just the last 64 chars. So, in this
> example, the save-as filename would be saved as a hidden file
> ".file.name-....txt".
> 
> Perhaps a better solution would be to truncate the *middle* of the
> filename, thus preserving the beginning and file extension?

The attached patch does this, and inserts an ellipsis to indicate that
something was replaced. The above URL becomes

dillo.long.file.name-0.69_r133...789012345678901234567890123.txt

which is 64 characters long.

I like this approach, because both the beginning and the end are the
most characteristic parts of a filename.

Sebastian

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
limit_filename_length.diff (text/x-diff, 1.1 KB)
diff -r 64870e59bceb src/uicmd.cc
--- a/src/uicmd.cc	Sat Jun 15 10:24:57 2013 +0200
+++ b/src/uicmd.cc	Sat Jun 15 14:05:05 2013 +0200
@@ -813,6 +813,9 @@
 static char *UIcmd_make_save_filename(const DilloUrl *url)
 {
    size_t MaxLen = 64;
+   const char *ellipsis = "...";
+   size_t ellipsisLen = strlen (ellipsis);
+
    const char *dir = save_dir, *path, *path2, *query;
    char *name, *free1, *free2, *n1, *n2;
 
@@ -823,9 +826,18 @@
    path2 = strrchr(path, '/');
    path = path2 ? path2 + 1 : path;
 
-   /* truncate the path if necessary */
+   /* replace the middle of the path by an ellipsis if necessary */
    if (strlen(path) > MaxLen) {
-      path = free1 = dStrndup(path, MaxLen);
+      /* "+ 1" because of rounding errors */
+      int len1 = (MaxLen - ellipsisLen) / 2;
+      int len2 = (MaxLen - ellipsisLen + 1) / 2;
+      char *part1 = dStrndup(path, len1);
+      char *part2 = dStrndup(path + strlen(path) - len2, len2);
+    
+      path = free1 = dStrconcat (part1, ellipsis, part2, NULL);
+
+      dFree(part1);
+      dFree(part2);
    }
 
    /* is there a query? */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.