Retain orig. filename as suffix for tmp. filename
- From: Adam Byrtek / alpha <alpha student uci agh edu pl>
- To: mc-devel gnome org
- Subject: Retain orig. filename as suffix for tmp. filename
- Date: Mon, 24 Feb 2003 01:39:44 +0100
It is useful to have an original filename as a part of temporary
filename when editing files from extfs or vfs:
* editors can use it's features connected to file name/extension
(syntax highlihting etc.)
* user can see the real name of the file he is editing in external
editor
I've created simple patch to extract 'foofile.tgz' as
* for the default getlocalcopy (used by most vfses):
vfsXXXXX-foofile.tgz, or vfsXXXXX when the earlier fails
(not mclocalcopy which is longer and not more informative)
* for the extfs_open:
extfsXXXXX-foofile.tgz, or extfsXXXXX when the earlier fails
It is worth noting, that the getlocalcopy has already supported file
'extension' as a suffix (mclocalcopyXXXXX.tgz in our case, btw it was
implemented in a quite ugly way: 6 lines of code could be easily
substituted with simple strrchr), but it is not enough IMO:
* Something we call 'extension' is not native to the *nix
nomenclature, in unix filename is atomic (of course we treat part
after the last dot as the 'extension', but it is mostly
conventional) - AFAIK, correct me if I'm wrong...
* The complete filename is more informative (see the second point at
the beginning).
Patch in the BTS (also attached):
https://savannah.gnu.org/patch/index.php?func=detailpatch&patch_id=1167&group_id=3521
--
_.|._ |_ _. : Adam Byrtek /alpha/
(_|||_)| |(_| : email alpha@(irc.pl|debian.org)
| : jabber alpha.pl(at)jabber.org, pgp 0xB25952C0
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/mc/vfs/ChangeLog,v
retrieving revision 1.583
diff -u -r1.583 ChangeLog
--- ChangeLog 19 Feb 2003 14:04:35 -0000 1.583
+++ ChangeLog 24 Feb 2003 00:20:34 -0000
@@ -1,0 +1,6 @@
+2003-02-24 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.
+
Index: extfs.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/extfs.c,v
retrieving revision 1.66
diff -u -r1.66 extfs.c
--- extfs.c 25 Dec 2002 21:42:59 -0000 1.66
+++ extfs.c 24 Feb 2003 00:20:34 -0000
@@ -659,9 +659,15 @@
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 just in case */
+ local_handle = mc_mkstemps (&local_filename, "extfs", NULL);
+ g_free (suffix);
if (local_handle == -1)
return NULL;
Index: vfs.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/vfs.c,v
retrieving revision 1.108
diff -u -r1.108 vfs.c
--- vfs.c 19 Feb 2003 08:38:49 -0000 1.108
+++ vfs.c 24 Feb 2003 00:20:34 -0000
@@ -1052,29 +1052,26 @@
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==PATH_SEP)
+ basename++;
+ suffix = g_strconcat("-", basename, NULL);
- if (!isalnum((unsigned char) *ptr))
- break;
- }
+ if ((fdout = mc_mkstemps (&tmp, "vfs", suffix)) == -1)
+ fdout = mc_mkstemps (&tmp, "vfs", NULL); /* fallback just in case */
+ g_free (suffix);
- fdout = mc_mkstemps (&tmp, "mclocalcopy", ext);
+
if (fdout == -1)
goto fail;
while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0){
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]