Browse Source

* extfs.c (extfs_open): Retain original filename as a suffix
for the temporary filename.
* vfs.c (mc_def_getlocalcopy): Likewise.

Pavel Roskin 22 years ago
parent
commit
6df9219f85
3 changed files with 43 additions and 26 deletions
  1. 6 0
      vfs/ChangeLog
  2. 13 5
      vfs/extfs.c
  3. 24 21
      vfs/vfs.c

+ 6 - 0
vfs/ChangeLog

@@ -1,3 +1,9 @@
+2003-02-26  Adam Byrtek  <alpha@debian.org>
+
+	* extfs.c (extfs_open): Retain original filename as a suffix
+	for the temporary filename.
+	* vfs.c (mc_def_getlocalcopy): Likewise.
+
 2003-02-24  Adam Byrtek  <alpha@debian.org>
 
 	* extfs/patchfs.in: rm and proper copyin support, more

+ 13 - 5
vfs/extfs.c

@@ -633,7 +633,7 @@ extfs_run (char *file)
 }
 
 static void *
-extfs_open (vfs * me, char *file, int flags, int mode)
+extfs_open (vfs *me, char *file, int flags, int mode)
 {
     struct pseudofile *extfs_info;
     struct archive *archive;
@@ -659,9 +659,17 @@ extfs_open (vfs * me, char *file, int flags, int mode)
 	ERRNOR (EISDIR, NULL);
 
     if (entry->inode->local_filename == NULL) {
-	char *local_filename;
+	char *local_filename, *suffix;
 
-	local_handle = mc_mkstemps (&local_filename, "extfs", NULL);
+	/* retain original filename as a suffix for a temporary filename */
+	suffix = g_strconcat ("-", entry->name, NULL);
+
+	if ((local_handle =
+	     mc_mkstemps (&local_filename, "extfs", suffix)) == -1) {
+	    /* fallback for the case if the filename is too long */
+	    local_handle = mc_mkstemps (&local_filename, "extfs", NULL);
+	}
+	g_free (suffix);
 
 	if (local_handle == -1)
 	    return NULL;
@@ -677,8 +685,8 @@ extfs_open (vfs * me, char *file, int flags, int mode)
 	entry->inode->local_filename = local_filename;
     }
 
-    local_handle = open (entry->inode->local_filename, NO_LINEAR (flags),
-			 mode);
+    local_handle =
+	open (entry->inode->local_filename, NO_LINEAR (flags), mode);
     if (local_handle == -1)
 	ERRNOR (EIO, NULL);
 

+ 24 - 21
vfs/vfs.c

@@ -1052,32 +1052,33 @@ mc_munmap (caddr_t addr, size_t len)
 char *
 mc_def_getlocalcopy (vfs *vfs, char *filename)
 {
-    char *tmp;
+    char *tmp, *suffix, *basename;
     int fdin, fdout, i;
     char buffer[8192];
     struct stat mystat;
-    char *ext = NULL;
-    char *ptr;
 
     fdin = mc_open (filename, O_RDONLY);
     if (fdin == -1)
-        return NULL;
+	return NULL;
 
-    /* Try to preserve existing extension */
-    for (ptr = filename + strlen(filename) - 1; ptr >= filename; ptr--) {
-	if (*ptr == '.') {
-	    ext = ptr;
-	    break;
-	}
+    /* retain original filename as a suffix for a temporary filename */
+    basename = strrchr (filename, PATH_SEP);
+    if (!basename)
+	basename = filename;
+    else
+	basename++;
 
-	if (!isalnum((unsigned char) *ptr))
-	    break;
+    suffix = g_strconcat ("-", basename, NULL);
+
+    if ((fdout = mc_mkstemps (&tmp, "vfs", suffix)) == -1) {
+	/* fallback for the case if the filename is too long */
+	fdout = mc_mkstemps (&tmp, "vfs", NULL);
     }
+    g_free (suffix);
 
-    fdout = mc_mkstemps (&tmp, "mclocalcopy", ext);
     if (fdout == -1)
 	goto fail;
-    while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0){
+    while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0) {
 	if (write (fdout, buffer, i) != i)
 	    goto fail;
     }
@@ -1085,19 +1086,21 @@ mc_def_getlocalcopy (vfs *vfs, char *filename)
 	goto fail;
     i = mc_close (fdin);
     fdin = -1;
-    if (i==-1)
+    if (i == -1)
 	goto fail;
-    if (close (fdout)==-1)
+    if (close (fdout) == -1)
 	goto fail;
 
-    if (mc_stat (filename, &mystat) != -1){
-        chmod (tmp, mystat.st_mode);
+    if (mc_stat (filename, &mystat) != -1) {
+	chmod (tmp, mystat.st_mode);
     }
     return tmp;
 
- fail:
-    if (fdout) close(fdout);
-    if (fdin) mc_close (fdin);
+  fail:
+    if (fdout)
+	close (fdout);
+    if (fdin)
+	mc_close (fdin);
     g_free (tmp);
     return NULL;
 }