fix stat breakage
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2870 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
родитель
cb8d845ad7
Коммит
6a74c9224c
39
src/files.c
39
src/files.c
@ -77,6 +77,9 @@ void delete_opennode(openfilestruct *fileptr)
|
|||||||
|
|
||||||
free(fileptr->filename);
|
free(fileptr->filename);
|
||||||
free_filestruct(fileptr->fileage);
|
free_filestruct(fileptr->fileage);
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
free(fileptr->current_stat);
|
||||||
|
#endif
|
||||||
free(fileptr);
|
free(fileptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +148,7 @@ void initialize_buffer(void)
|
|||||||
|
|
||||||
openfile->fmt = NIX_FILE;
|
openfile->fmt = NIX_FILE;
|
||||||
|
|
||||||
memset(&openfile->originalfilestat, 0, sizeof(struct stat));
|
openfile->current_stat = NULL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
openfile->colorstrings = NULL;
|
openfile->colorstrings = NULL;
|
||||||
@ -162,6 +165,10 @@ void reinitialize_buffer(void)
|
|||||||
|
|
||||||
free_filestruct(openfile->fileage);
|
free_filestruct(openfile->fileage);
|
||||||
|
|
||||||
|
#ifndef NANO_SMALL
|
||||||
|
free(openfile->current_stat);
|
||||||
|
#endif
|
||||||
|
|
||||||
initialize_buffer();
|
initialize_buffer();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -205,12 +212,16 @@ void open_buffer(const char *filename)
|
|||||||
if (rc != -1 && new_buffer)
|
if (rc != -1 && new_buffer)
|
||||||
openfile->filename = mallocstrcpy(openfile->filename, filename);
|
openfile->filename = mallocstrcpy(openfile->filename, filename);
|
||||||
|
|
||||||
/* If we have a non-new file, read it in and update its stat, if
|
/* If we have a non-new file, read it in. Then, if the buffer has
|
||||||
* applicable. */
|
* no stat, update the stat, if applicable. */
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
read_file(f, filename);
|
read_file(f, filename);
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
stat(filename, &openfile->originalfilestat);
|
if (openfile->current_stat == NULL) {
|
||||||
|
openfile->current_stat =
|
||||||
|
(struct stat *)nmalloc(sizeof(struct stat));
|
||||||
|
stat(filename, openfile->current_stat);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1291,7 +1302,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
|
|||||||
* only if the file has not been modified by someone else since nano
|
* only if the file has not been modified by someone else since nano
|
||||||
* opened it. */
|
* opened it. */
|
||||||
if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append != 0 ||
|
if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append != 0 ||
|
||||||
openfile->mark_set) || openfile->originalfilestat.st_mtime ==
|
openfile->mark_set) || openfile->current_stat->st_mtime ==
|
||||||
st.st_mtime)) {
|
st.st_mtime)) {
|
||||||
FILE *backup_file;
|
FILE *backup_file;
|
||||||
char *backupname;
|
char *backupname;
|
||||||
@ -1299,8 +1310,8 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
|
|||||||
int copy_status;
|
int copy_status;
|
||||||
|
|
||||||
/* Save the original file's access and modification times. */
|
/* Save the original file's access and modification times. */
|
||||||
filetime.actime = openfile->originalfilestat.st_atime;
|
filetime.actime = openfile->current_stat->st_atime;
|
||||||
filetime.modtime = openfile->originalfilestat.st_mtime;
|
filetime.modtime = openfile->current_stat->st_mtime;
|
||||||
|
|
||||||
if (f_open == NULL) {
|
if (f_open == NULL) {
|
||||||
/* Open the original file to copy to the backup. */
|
/* Open the original file to copy to the backup. */
|
||||||
@ -1365,7 +1376,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
|
|||||||
backup_file = fopen(backupname, "wb");
|
backup_file = fopen(backupname, "wb");
|
||||||
|
|
||||||
if (backup_file == NULL || chmod(backupname,
|
if (backup_file == NULL || chmod(backupname,
|
||||||
openfile->originalfilestat.st_mode) == -1) {
|
openfile->current_stat->st_mode) == -1) {
|
||||||
statusbar(_("Error writing %s: %s"), backupname,
|
statusbar(_("Error writing %s: %s"), backupname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
free(backupname);
|
free(backupname);
|
||||||
@ -1384,8 +1395,8 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
|
|||||||
|
|
||||||
/* And set metadata. */
|
/* And set metadata. */
|
||||||
if (copy_status != 0 || chown(backupname,
|
if (copy_status != 0 || chown(backupname,
|
||||||
openfile->originalfilestat.st_uid,
|
openfile->current_stat->st_uid,
|
||||||
openfile->originalfilestat.st_gid) == -1 ||
|
openfile->current_stat->st_gid) == -1 ||
|
||||||
utime(backupname, &filetime) == -1) {
|
utime(backupname, &filetime) == -1) {
|
||||||
free(backupname);
|
free(backupname);
|
||||||
if (copy_status == -1)
|
if (copy_status == -1)
|
||||||
@ -1589,9 +1600,13 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* Update originalfilestat to reference the file as it is now. */
|
/* Update current_stat to reference the file as it is now. */
|
||||||
stat(realname, &openfile->originalfilestat);
|
if (openfile->current_stat == NULL)
|
||||||
|
openfile->current_stat =
|
||||||
|
(struct stat *)nmalloc(sizeof(struct stat));
|
||||||
|
stat(realname, openfile->current_stat);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
statusbar(P_("Wrote %lu line", "Wrote %lu lines",
|
statusbar(P_("Wrote %lu line", "Wrote %lu lines",
|
||||||
(unsigned long)lineswritten),
|
(unsigned long)lineswritten),
|
||||||
(unsigned long)lineswritten);
|
(unsigned long)lineswritten);
|
||||||
|
@ -217,8 +217,7 @@ typedef struct openfilestruct {
|
|||||||
size_t mark_begin_x; /* Current file's beginning marked
|
size_t mark_begin_x; /* Current file's beginning marked
|
||||||
* line's x-coordinate position. */
|
* line's x-coordinate position. */
|
||||||
file_format fmt; /* Current file's format. */
|
file_format fmt; /* Current file's format. */
|
||||||
struct stat originalfilestat;
|
struct stat *current_stat; /* Current file's stat. */
|
||||||
/* Current file's stat. */
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
colortype *colorstrings; /* Current file's associated colors. */
|
colortype *colorstrings; /* Current file's associated colors. */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user