ajbj patch round-up
[nedit-bw.git] / keep_state_for_bck_file.patch
blobd926e6f1eb912d472f108422feeac83858e6932d
1 Subject: keep the file times for backup files
3 ---
5 source/file.c | 18 ++++++++++++++++--
6 1 file changed, 16 insertions(+), 2 deletions(-)
8 diff --quilt old/source/file.c new/source/file.c
9 --- old/source/file.c
10 +++ new/source/file.c
11 @@ -67,10 +67,11 @@ static const char CVSID[] = "$Id: file.c
12 #ifndef __MVS__
13 #include <sys/param.h>
14 #endif
15 #include <fcntl.h>
16 #endif /*VMS*/
17 +#include <utime.h>
19 #include <Xm/Xm.h>
20 #include <Xm/ToggleB.h>
21 #include <Xm/FileSB.h>
22 #include <Xm/RowColumn.h>
23 @@ -1359,10 +1360,11 @@ static int writeBckVersion(WindowInfo *w
24 #ifndef VMS
25 char fullname[MAXPATHLEN], bckname[MAXPATHLEN];
26 struct stat statbuf;
27 int in_fd, out_fd;
28 char *io_buffer;
29 + struct utimbuf utimbuf;
30 #define IO_BUFFER_SIZE ((size_t)(1024*1024))
32 /* Do only if version backups are turned on */
33 if (!window->saveOldVersion) {
34 return False;
35 @@ -1388,12 +1390,12 @@ static int writeBckVersion(WindowInfo *w
36 if (in_fd<0) {
37 return FALSE;
40 /* Get permissions of the file.
41 - We preserve the normal permissions but not ownership, extended
42 - attributes, et cetera. */
43 + We preserve the normal permissions but not extended attributes,
44 + et cetera. */
45 if (fstat(in_fd, &statbuf) != 0) {
46 return FALSE;
49 /* open the destination file exclusive and with restrictive permissions. */
50 @@ -1408,10 +1410,18 @@ static int writeBckVersion(WindowInfo *w
51 close(out_fd);
52 remove(bckname);
53 return bckError(window, "fchmod() failed", bckname);
56 + /* Set ownership on new file */
57 + if (fchown(out_fd, statbuf.st_uid, statbuf.st_gid) != 0) {
58 + close(in_fd);
59 + close(out_fd);
60 + remove(bckname);
61 + return bckError(window, "fchown() failed", bckname);
62 + }
64 /* Allocate I/O buffer */
65 io_buffer = (char*) malloc(IO_BUFFER_SIZE);
66 if (NULL == io_buffer) {
67 close(in_fd);
68 close(out_fd);
69 @@ -1452,10 +1462,14 @@ static int writeBckVersion(WindowInfo *w
70 close(in_fd);
71 close(out_fd);
73 free(io_buffer);
75 + utimbuf.actime = statbuf.st_atime;
76 + utimbuf.modtime = statbuf.st_mtime;
77 + utime(bckname, &utimbuf);
79 #endif /* VMS */
81 return FALSE;