diff options
Diffstat (limited to 'src/fileio.c')
-rw-r--r-- | src/fileio.c | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/src/fileio.c b/src/fileio.c index be52d0f3d0e..a46cfc7ac69 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -316,7 +316,7 @@ use the standard functions without calling themselves recursively. */) } } - QUIT; + maybe_quit (); } return result; } @@ -1960,9 +1960,9 @@ permissions. */) report_file_error ("Copying permissions to", newname); } #else /* not WINDOWSNT */ - immediate_quit = 1; + immediate_quit = true; ifd = emacs_open (SSDATA (encoded_file), O_RDONLY, 0); - immediate_quit = 0; + immediate_quit = false; if (ifd < 0) report_file_error ("Opening input file", file); @@ -2024,8 +2024,8 @@ permissions. */) oldsize = out_st.st_size; } - immediate_quit = 1; - QUIT; + immediate_quit = true; + maybe_quit (); if (clone_file (ofd, ifd)) newsize = st.st_size; @@ -2047,7 +2047,7 @@ permissions. */) if (newsize < oldsize && ftruncate (ofd, newsize) != 0) report_file_error ("Truncating output file", newname); - immediate_quit = 0; + immediate_quit = false; #ifndef MSDOS /* Preserve the original file permissions, and if requested, also its @@ -2682,7 +2682,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, DEFUN ("access-file", Faccess_file, Saccess_file, 2, 2, 0, doc: /* Access file FILENAME, and get an error if that does not work. -The second argument STRING is used in the error message. +The second argument STRING is prepended to the error message. If there is no error, returns nil. */) (Lisp_Object filename, Lisp_Object string) { @@ -2815,7 +2815,17 @@ really is a readable and searchable directory. */) if (!NILP (handler)) { Lisp_Object r = call2 (handler, Qfile_accessible_directory_p, absname); - errno = 0; + + /* Set errno in case the handler failed. EACCES might be a lie + (e.g., the directory might not exist, or be a regular file), + but at least it does TRT in the "usual" case of an existing + directory that is not accessible by the current user, and + avoids reporting "Success" for a failed operation. Perhaps + someday we can fix this in a better way, by improving + file-accessible-directory-p's API; see Bug#25419. */ + if (!EQ (r, Qt)) + errno = EACCES; + return r; } @@ -3393,13 +3403,13 @@ read_non_regular (Lisp_Object state) { int nbytes; - immediate_quit = 1; - QUIT; + immediate_quit = true; + maybe_quit (); nbytes = emacs_read (XSAVE_INTEGER (state, 0), ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + XSAVE_INTEGER (state, 1)), XSAVE_INTEGER (state, 2)); - immediate_quit = 0; + immediate_quit = false; /* Fast recycle this object for the likely next call. */ free_misc (state); return make_number (nbytes); @@ -3858,8 +3868,8 @@ by calling `format-decode', which see. */) report_file_error ("Setting file position", orig_filename); } - immediate_quit = 1; - QUIT; + immediate_quit = true; + maybe_quit (); /* Count how many chars at the start of the file match the text at the beginning of the buffer. */ while (1) @@ -3910,7 +3920,7 @@ by calling `format-decode', which see. */) goto handled; } immediate_quit = true; - QUIT; + maybe_quit (); /* Count how many chars at the end of the file match the text at the end of the buffer. But, if we have already found that decoding is necessary, don't waste time. */ @@ -3967,7 +3977,7 @@ by calling `format-decode', which see. */) if (nread == 0) break; } - immediate_quit = 0; + immediate_quit = false; if (! giveup_match_end) { @@ -4065,11 +4075,11 @@ by calling `format-decode', which see. */) quitting while reading a huge file. */ /* Allow quitting out of the actual I/O. */ - immediate_quit = 1; - QUIT; + immediate_quit = true; + maybe_quit (); this = emacs_read (fd, read_buf + unprocessed, READ_BUF_SIZE - unprocessed); - immediate_quit = 0; + immediate_quit = false; if (this <= 0) break; @@ -4284,13 +4294,13 @@ by calling `format-decode', which see. */) /* Allow quitting out of the actual I/O. We don't make text part of the buffer until all the reading is done, so a C-g here doesn't do any harm. */ - immediate_quit = 1; - QUIT; + immediate_quit = true; + maybe_quit (); this = emacs_read (fd, ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted), trytry); - immediate_quit = 0; + immediate_quit = false; } if (this <= 0) @@ -4602,7 +4612,7 @@ by calling `format-decode', which see. */) } } - QUIT; + maybe_quit (); p = XCDR (p); } @@ -4992,7 +5002,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, } } - immediate_quit = 1; + immediate_quit = true; if (STRINGP (start)) ok = a_write (desc, start, 0, SCHARS (start), &annotations, &coding); @@ -5016,7 +5026,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, save_errno = errno; } - immediate_quit = 0; + immediate_quit = false; /* fsync is not crucial for temporary files. Nor for auto-save files, since they might lose some work anyway. */ @@ -5142,19 +5152,26 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, if (! ok) report_file_errno ("Write error", filename, save_errno); + bool auto_saving_into_visited_file = + auto_saving + && ! NILP (Fstring_equal (BVAR (current_buffer, filename), + BVAR (current_buffer, auto_save_file_name))); if (visiting) { SAVE_MODIFF = MODIFF; XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG); bset_filename (current_buffer, visit_file); update_mode_lines = 14; + if (auto_saving_into_visited_file) + unlock_file (lockname); } else if (quietly) { - if (auto_saving - && ! NILP (Fstring_equal (BVAR (current_buffer, filename), - BVAR (current_buffer, auto_save_file_name)))) - SAVE_MODIFF = MODIFF; + if (auto_saving_into_visited_file) + { + SAVE_MODIFF = MODIFF; + unlock_file (lockname); + } return Qnil; } |