mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
* 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:
parent
9ec797a024
commit
6df9219f85
@ -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
|
||||
|
14
vfs/extfs.c
14
vfs/extfs.c
@ -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);
|
||||
|
||||
|
33
vfs/vfs.c
33
vfs/vfs.c
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user