From bee6f71ac3e6812693248dc4c3698b7a67c3c4b3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 15 Aug 2024 20:10:53 -0700 Subject: [PATCH] Port better to NFS unlink MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I found this problem while looking into Bug#72641. * lib-src/etags.c (do_move_file): * lib-src/update-game-score.c (unlock_file): * src/androidvfs.c (android_hack_asset_fd_fallback): * src/filelock.c (current_lock_owner): Treat unlink as successful if it fails because the file wasn’t there. This can happen with some NFS implementations, due to its retrying over the network to get at-least-once semantics. Although most of Emacs’s calls to unlink were already doing this, a few instances were not. (cherry picked from commit 40eecd594ac60f38b6729fd9cf3474a8b9d133b9) --- lib-src/etags.c | 2 +- lib-src/update-game-score.c | 2 +- src/androidvfs.c | 2 +- src/filelock.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib-src/etags.c b/lib-src/etags.c index 03bc55de03d..edadbc25901 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -7812,7 +7812,7 @@ do_move_file (const char *src_file, const char *dst_file) if (fclose (dst_f) == EOF) pfatal (dst_file); - if (unlink (src_file) == -1) + if (unlink (src_file) < 0 && errno != ENOENT) pfatal ("unlink error"); return; diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 4139073bcd7..e3b24ad7717 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -497,7 +497,7 @@ unlock_file (const char *filename, void *state) char *lockpath = (char *) state; int saved_errno = errno; int ret = unlink (lockpath); - if (0 <= ret) + if (! (ret < 0 && errno != ENOENT)) errno = saved_errno; free (lockpath); return ret; diff --git a/src/androidvfs.c b/src/androidvfs.c index 14da8eed37e..ff81ef288f5 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c @@ -1323,7 +1323,7 @@ android_hack_asset_fd_fallback (AAsset *asset) if (fd < 0) return -1; - if (unlink (filename)) + if (unlink (filename) && errno != ENOENT) goto fail; if (ftruncate (fd, size)) diff --git a/src/filelock.c b/src/filelock.c index 1ae57dc7344..bc09fce69f8 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -501,7 +501,7 @@ current_lock_owner (lock_info_type *owner, Lisp_Object lfname) the file system is buggy, e.g., . Emacs never creates empty lock files even temporarily, so removing an empty lock file should be harmless. */ - return emacs_unlink (SSDATA (lfname)) < 0 ? errno : 0; + return emacs_unlink (SSDATA (lfname)) < 0 && errno != ENOENT ? errno : 0; } -- 2.39.2