commit 123110c5dc3e0d8c60a4ff0121056e301f503706
parent cbba77558e222eb0e91a8e88e76bbe2c9fa16042
Author: Chris Allegretta <chrisa@asty.org>
Date: Fri, 20 Nov 2009 05:09:12 +0000
2009-11-19 Chris Allegretta <chrisa@asty.org>
* nano.c (die_save_file) Try nd match the permissions of the file we were
editing but only make a minimal effort to do so. Fixes Savannah bug 27273
reported by Mike Frysinger.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4432 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,5 +1,10 @@
+2009-11-19 Chris Allegretta <chrisa@asty.org>
+ * nano.c (die_save_file) Try nd match the permissions of the file we were
+ editing but only make a minimal effort to do so. Fixes Savannah bug 27273
+ reported by Mike Frysinger.
+
2009-11-18 Adrian Bunk <bunk via Savannah>
- * nano.c (main) - Allow --fill and --nowrap to override nanorc entries and each other
+ * nano.c (main): Allow --fill and --nowrap to override nanorc entries and each other
on the command line.
2009-11-15 Chris Allegretta <chrisa@asty.org>
diff --git a/src/nano.c b/src/nano.c
@@ -638,7 +638,7 @@ void die(const char *msg, ...)
if (filepart != NULL)
unpartition_filestruct(&filepart);
- die_save_file(openfile->filename);
+ die_save_file(openfile->filename, openfile->current_stat);
}
#ifdef ENABLE_MULTIBUFFER
@@ -651,7 +651,7 @@ void die(const char *msg, ...)
/* Save the current file buffer if it's been modified. */
if (openfile->modified)
- die_save_file(openfile->filename);
+ die_save_file(openfile->filename, openfile->current_stat);
}
}
#endif
@@ -662,7 +662,7 @@ void die(const char *msg, ...)
/* Save the current file under the name spacified in die_filename, which
* is modified to be unique if necessary. */
-void die_save_file(const char *die_filename)
+void die_save_file(const char *die_filename, struct stat *die_stat)
{
char *retval;
bool failed = TRUE;
@@ -691,6 +691,15 @@ void die_save_file(const char *die_filename)
fprintf(stderr, _("\nBuffer not written: %s\n"),
_("Too many backup files?"));
+ /* Try and chmod/chown the save file to the values of the original file, but
+ dont worry if it fails because we're supposed to be bailing as fast
+ as possible. */
+ if (die_stat) {
+ int shush;
+ shush = chmod(retval, die_stat->st_mode);
+ shush = chown(retval, die_stat->st_uid, die_stat->st_gid);
+ }
+
free(retval);
}
diff --git a/src/proto.h b/src/proto.h
@@ -428,7 +428,7 @@ void free_openfilestruct(openfilestruct *src);
void print_view_warning(void);
void finish(void);
void die(const char *msg, ...);
-void die_save_file(const char *die_filename);
+void die_save_file(const char *die_filename, struct stat *die_stat);
void window_init(void);
#ifndef DISABLE_MOUSE
void disable_mouse_support(void);