* 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>
* extfs/patchfs.in: rm and proper copyin support, more

View File

@ -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;
/* 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);

View File

@ -1052,29 +1052,30 @@ 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;
/* 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) {
@ -1096,8 +1097,10 @@ mc_def_getlocalcopy (vfs *vfs, char *filename)
return tmp;
fail:
if (fdout) close(fdout);
if (fdin) mc_close (fdin);
if (fdout)
close (fdout);
if (fdin)
mc_close (fdin);
g_free (tmp);
return NULL;
}