suggestions

Pavel Roskin proski at gnu.org
Tue Feb 19 21:32:12 UTC 2002


Hello!

> > > This means that every time you enter a zip archive an view
> > > files in it, the archive is modified! This should also be true
> > > for all other archives supported via extfs.
> > 
> > Correction: It does happen when you view files with an ".html"
> > extension. The effect may be the same with other filetypes
> > as well. But regular text files files without extension are
> > not copied back into the archive!
> 
> I confirm this bug with the CVS version of MC.  It's a serious problem.
> It seems to be a bug either in the extfs implementation or in 
> exec_extension() (src/ext.c).

The problem is specific to extfs.  extfs_ungetlocalcopy() opens the file 
with O_WRONLY flag, but extfs_open() thinks that the file should be marked 
as changed just because of that.

In fact, extfs_ungetlocalcopy() only honors the "has_changed" flag in the 
code marked as "Should not happen" !!!

I believe that both functions are wrong.  The file should be marked as
changed only is in was created, not if because it was opened for writing.  

On the other hand, extfs_ungetlocalcopy() should open the file for reading
(i.e. not for writing), but has_changed should be set in the file flags if
it's set in the argument.

==============================
--- ChangeLog
+++ ChangeLog
@@ -1 +1,10 @@
+2002-02-19  Pavel Roskin  <proski at gnu.org>
+
+	* extfs.c (extfs_open): Only create a new entry if it has not
+	been found and O_CREAT is set.  Consider file as changed only
+	if it has been successfully created.
+	(extfs_getlocalcopy): Open file only for reading.  This prevents
+	marking file as changed.  Actually use the has_changed argument.
+	Reported by Nerijus Baliunas <nerijus at users.sourceforge.net>
+
 2002-02-12  Pavel Roskin  <proski at gnu.org>
--- extfs.c
+++ extfs.c
@@ -607,11 +607,16 @@ static void *extfs_open (vfs *me, char *
     char *mc_extfsdir;
     struct entry *entry;
     int local_handle;
-    const int do_create = (flags & O_ACCMODE) != O_RDONLY;
+    int created = 0;
     
     if ((q = get_path_mangle (file, &archive, 0, 0)) == NULL)
 	return NULL;
-    entry = find_entry (archive->root_entry, q, 0, do_create);
+    entry = find_entry (archive->root_entry, q, 0, 0);
+    if (entry == NULL && (flags & O_CREAT)) {
+	/* Create new entry */
+	entry = find_entry (archive->root_entry, q, 0, 1);
+	created = (entry != NULL);
+    }
     if (entry == NULL)
     	return NULL;
     if ((entry = my_resolve_symlinks (entry)) == NULL)
@@ -642,7 +647,7 @@ static void *extfs_open (vfs *me, char *
 	g_free (q);
 	g_free (mc_extfsdir);
 	g_free (archive_name);
-        if (my_system (EXECUTE_AS_SHELL | EXECUTE_SETUID | EXECUTE_WAIT, shell, cmd) && !do_create){
+        if (my_system (EXECUTE_AS_SHELL | EXECUTE_SETUID | EXECUTE_WAIT, shell, cmd) && !created){
             free (entry->inode->local_filename);
             entry->inode->local_filename = NULL;
             g_free (cmd);
@@ -658,7 +663,7 @@ static void *extfs_open (vfs *me, char *
     extfs_info = g_new (struct pseudofile, 1);
     extfs_info->archive = archive;
     extfs_info->entry = entry;
-    extfs_info->has_changed = do_create;
+    extfs_info->has_changed = created;
     extfs_info->local_handle = local_handle;
 
     /* i.e. we had no open files and now we have one */
@@ -1308,12 +1313,13 @@ static char *extfs_getlocalcopy (vfs *me
 static int extfs_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed)
 {
     struct pseudofile *fp = 
-        (struct pseudofile *) extfs_open (me, path, O_WRONLY, 0);
+        (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
     
     if (fp == NULL)
         return 0;
     if (!strcmp (fp->entry->inode->local_filename, local)) {
         fp->archive->fd_usage--;
+        fp->has_changed |= has_changed;
         extfs_close ((void *) fp);
         return 0;
     } else {
==============================

-- 
Regards,
Pavel Roskin




More information about the mc-devel mailing list