Okay, now the permissions should be fixed too
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@390 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
7b36c52efc
commit
1bd0ce2832
|
@ -13,6 +13,8 @@ General
|
||||||
- OOPS, line up link/unlink/rename check if conditional with
|
- OOPS, line up link/unlink/rename check if conditional with
|
||||||
top if conditional. Option -l has been broken for 9 versions,
|
top if conditional. Option -l has been broken for 9 versions,
|
||||||
no one noticed?!
|
no one noticed?!
|
||||||
|
- Added saving perms at end of link so we can apply them to the
|
||||||
|
new file if --nofollow is used.
|
||||||
- winio.c:
|
- winio.c:
|
||||||
edit_add()
|
edit_add()
|
||||||
- Off by one display error (fix by Rocco Corsi).
|
- Off by one display error (fix by Rocco Corsi).
|
||||||
|
|
43
files.c
43
files.c
|
@ -302,7 +302,7 @@ int write_file(char *name, int tmp)
|
||||||
char buf[PATH_MAX + 1];
|
char buf[PATH_MAX + 1];
|
||||||
filestruct *fileptr;
|
filestruct *fileptr;
|
||||||
int fd, mask = 0, realexists, anyexists;
|
int fd, mask = 0, realexists, anyexists;
|
||||||
struct stat st, st2;
|
struct stat st, lst, st2;
|
||||||
static char *realname = NULL;
|
static char *realname = NULL;
|
||||||
|
|
||||||
if (!strcmp(name, "")) {
|
if (!strcmp(name, "")) {
|
||||||
|
@ -321,13 +321,11 @@ int write_file(char *name, int tmp)
|
||||||
realname = mallocstrcpy(realname, name);
|
realname = mallocstrcpy(realname, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Save the state of file at the end of the symlink */
|
/* Save the state of file at the end of the symlink (if there is one) */
|
||||||
realexists = stat(realname, &st);
|
realexists = stat(realname, &st);
|
||||||
|
|
||||||
/* Check to see if the file is a regular file and FOLLOW_SYMLINKS is
|
/* Stat the link itself for the check... */
|
||||||
set. If so then don't do the delete and recreate code which would
|
anyexists = lstat(realname, &lst);
|
||||||
cause unexpected behavior */
|
|
||||||
anyexists = lstat(realname, &st);
|
|
||||||
|
|
||||||
/* New case: if the file exists, just give up */
|
/* New case: if the file exists, just give up */
|
||||||
if (tmp && anyexists != -1)
|
if (tmp && anyexists != -1)
|
||||||
|
@ -335,7 +333,7 @@ int write_file(char *name, int tmp)
|
||||||
/* NOTE: If you change this statement, you MUST CHANGE the if
|
/* NOTE: If you change this statement, you MUST CHANGE the if
|
||||||
statement below (that starts "if ((!ISSET(FOLLOW_SYMLINKS)...")
|
statement below (that starts "if ((!ISSET(FOLLOW_SYMLINKS)...")
|
||||||
to reflect whether or not to link/unlink/rename the file */
|
to reflect whether or not to link/unlink/rename the file */
|
||||||
else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(st.st_mode)) {
|
else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(lst.st_mode) || tmp) {
|
||||||
|
|
||||||
/* Use O_EXCL if tmp == 1, I suppose */
|
/* Use O_EXCL if tmp == 1, I suppose */
|
||||||
if (tmp)
|
if (tmp)
|
||||||
|
@ -434,8 +432,9 @@ int write_file(char *name, int tmp)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(st.st_mode)) || tmp) {
|
if (realexists == -1 || tmp ||
|
||||||
if (realexists == -1) {
|
(!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) {
|
||||||
|
|
||||||
/* Use default umask as file permisions if file is a new file. */
|
/* Use default umask as file permisions if file is a new file. */
|
||||||
mask = umask(0);
|
mask = umask(0);
|
||||||
umask(mask);
|
umask(mask);
|
||||||
|
@ -444,10 +443,11 @@ int write_file(char *name, int tmp)
|
||||||
mask = 0600;
|
mask = 0600;
|
||||||
else
|
else
|
||||||
mask = 0666 & ~mask;
|
mask = 0666 & ~mask;
|
||||||
|
} else
|
||||||
} else {
|
|
||||||
/* Use permissions from file we are overwriting. */
|
|
||||||
mask = st.st_mode;
|
mask = st.st_mode;
|
||||||
|
|
||||||
|
if (!tmp && (!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) {
|
||||||
|
/* Use permissions from file we are overwriting. */
|
||||||
if (unlink(realname) == -1) {
|
if (unlink(realname) == -1) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
statusbar(_("Could not open %s for writing: %s"),
|
statusbar(_("Could not open %s for writing: %s"),
|
||||||
|
@ -456,9 +456,6 @@ int write_file(char *name, int tmp)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!tmp) {
|
|
||||||
if (link(buf, realname) != -1)
|
if (link(buf, realname) != -1)
|
||||||
unlink(buf);
|
unlink(buf);
|
||||||
else if (errno != EPERM) {
|
else if (errno != EPERM) {
|
||||||
|
@ -477,7 +474,6 @@ int write_file(char *name, int tmp)
|
||||||
statusbar(_("Could not set permissions %o on %s: %s"),
|
statusbar(_("Could not set permissions %o on %s: %s"),
|
||||||
mask, realname, strerror(errno));
|
mask, realname, strerror(errno));
|
||||||
|
|
||||||
}
|
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
strncpy(filename, realname, 132);
|
strncpy(filename, realname, 132);
|
||||||
statusbar(_("Wrote %d lines"), lineswritten);
|
statusbar(_("Wrote %d lines"), lineswritten);
|
||||||
|
@ -521,7 +517,8 @@ int do_writeout(int exiting)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NANO_EXTRA
|
#ifdef NANO_EXTRA
|
||||||
if (exiting && !ISSET(TEMP_OPT) && !strcasecmp(answer, "zzy") && !did_cred) {
|
if (exiting && !ISSET(TEMP_OPT) && !strcasecmp(answer, "zzy")
|
||||||
|
&& !did_cred) {
|
||||||
do_credits();
|
do_credits();
|
||||||
did_cred = 1;
|
did_cred = 1;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -573,21 +570,20 @@ char *real_dir_from_tilde (char *buf)
|
||||||
|
|
||||||
sprintf(dirtmp, "%s/%s", getenv("HOME"), &buf[2]);
|
sprintf(dirtmp, "%s/%s", getenv("HOME"), &buf[2]);
|
||||||
}
|
}
|
||||||
}
|
} else if (buf[1] != 0) {
|
||||||
else if (buf[1] != 0) {
|
|
||||||
|
|
||||||
if ((fd = open("/etc/passwd", O_RDONLY)) == -1)
|
if ((fd = open("/etc/passwd", O_RDONLY)) == -1)
|
||||||
goto abort;
|
goto abort;
|
||||||
|
|
||||||
/* Figure how how much of of the str we need to compare */
|
/* Figure how how much of of the str we need to compare */
|
||||||
for (searchctr = 1; buf[searchctr] != '/' &&
|
for (searchctr = 1; buf[searchctr] != '/' &&
|
||||||
buf[searchctr] != 0; searchctr++)
|
buf[searchctr] != 0; searchctr++);
|
||||||
;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
i = 0;
|
i = 0;
|
||||||
line = nmalloc(1);
|
line = nmalloc(1);
|
||||||
while ((status = read(fd, byte, 1)) != 0 && byte[0] != '\n') {
|
while ((status = read(fd, byte, 1)) != 0
|
||||||
|
&& byte[0] != '\n') {
|
||||||
|
|
||||||
line[i] = byte[0];
|
line[i] = byte[0];
|
||||||
i++;
|
i++;
|
||||||
|
@ -622,8 +618,7 @@ char *real_dir_from_tilde (char *buf)
|
||||||
|
|
||||||
} while (status != 0);
|
} while (status != 0);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
dirtmp = mallocstrcpy(dirtmp, buf);
|
dirtmp = mallocstrcpy(dirtmp, buf);
|
||||||
|
|
||||||
return dirtmp;
|
return dirtmp;
|
||||||
|
|
Loading…
Reference in New Issue