* extfs.c (extfs_open): Retain original filename as a suffix

for the temporary filename.
* vfs.c (mc_def_getlocalcopy): Likewise.
This commit is contained in:
Pavel Roskin 2003-02-26 17:43:18 +00:00
parent 9ec797a024
commit 6df9219f85
3 changed files with 43 additions and 26 deletions

View File

@ -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> 2003-02-24 Adam Byrtek <alpha@debian.org>
* extfs/patchfs.in: rm and proper copyin support, more * extfs/patchfs.in: rm and proper copyin support, more

View File

@ -633,7 +633,7 @@ extfs_run (char *file)
} }
static void * 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 pseudofile *extfs_info;
struct archive *archive; struct archive *archive;
@ -659,9 +659,17 @@ extfs_open (vfs * me, char *file, int flags, int mode)
ERRNOR (EISDIR, NULL); ERRNOR (EISDIR, NULL);
if (entry->inode->local_filename == 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) if (local_handle == -1)
return NULL; return NULL;
@ -677,8 +685,8 @@ extfs_open (vfs * me, char *file, int flags, int mode)
entry->inode->local_filename = local_filename; entry->inode->local_filename = local_filename;
} }
local_handle = open (entry->inode->local_filename, NO_LINEAR (flags), local_handle =
mode); open (entry->inode->local_filename, NO_LINEAR (flags), mode);
if (local_handle == -1) if (local_handle == -1)
ERRNOR (EIO, NULL); ERRNOR (EIO, NULL);

View File

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