Re: More on tilde expansion



Hi,

I wrote:
> The problem appears to originate from file_mask_dialog() in
> src/filegui.c (gdb shows dest_dir = g_strdup ("./") gets called for
> single file copies to locations without a slash), but the logic of that
> function is still rather incomprehensible to me...
> 
> Fe, look at
>     orig_mask = ctx->dest_mask;
> ...
> 	ctx->dest_mask = g_strdup (ctx->dest_mask);
> 	*orig_mask = 0;

The use of orig_mask in this example is needless and wrong, as instead
of "nulling" the string dest_dir (which orig_mask is pointing to) should
be g_freed.

Anyway, I think I finally got it. Since the ctx->dest_mask should also
be tilde expanded (preferably before it is construed from dest_dir) the
easiest solution is to move the tilde_expand to file_mask_dialog() in
src/filegui.c so this function returns tilde expanded values. See
attached patch (against CVS-20040915) for details (and please verify its
validity).

Leonard.

-- 
mount -t life -o ro /dev/dna /genetic/research

--- src/filegui.c.000	2004-09-03 14:40:08.000000000 +0200
+++ src/filegui.c	2004-09-15 14:15:41.000000000 +0200
@@ -914,8 +914,7 @@ file_mask_dialog (FileOpContext *ctx, Fi
 
     orig_mask = source_mask;
     if (!dest_dir || !*dest_dir) {
-	if (source_mask)
-	    g_free (source_mask);
+	g_free (source_mask);
 	return dest_dir;
     }
     if (source_easy_patterns) {
@@ -935,18 +934,18 @@ file_mask_dialog (FileOpContext *ctx, Fi
     if (error) {
 	message (1, MSG_ERROR, _("Invalid source pattern `%s' \n %s "),
 		    orig_mask, error);
-	if (orig_mask)
-	    g_free (orig_mask);
+	g_free (orig_mask);
 	goto ask_file_mask;
     }
-    if (orig_mask)
-	g_free (orig_mask);
+    g_free (orig_mask);
+    char *tmpdest = dest_dir;
+    dest_dir = tilde_expand(tmpdest);
+    g_free(tmpdest);
     ctx->dest_mask = strrchr (dest_dir, PATH_SEP);
     if (ctx->dest_mask == NULL)
 	ctx->dest_mask = dest_dir;
     else
 	ctx->dest_mask++;
-    orig_mask = ctx->dest_mask;
     if (!*ctx->dest_mask
 	|| (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask)
 	    && (!only_one
@@ -957,8 +956,9 @@ file_mask_dialog (FileOpContext *ctx, Fi
 		    && S_ISDIR (buf.st_mode)))))
 	ctx->dest_mask = g_strdup ("*");
     else {
-	ctx->dest_mask = g_strdup (ctx->dest_mask);
-	*orig_mask = 0;
+	ctx->dest_mask = g_strdup(ctx->dest_mask);
+	g_free(dest_dir);
+	dest_dir = g_strdup ("./");
     }
     if (!*dest_dir) {
 	g_free (dest_dir);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]