diff --git a/pkgs/racket-doc/scribblings/reference/filesystem.scrbl b/pkgs/racket-doc/scribblings/reference/filesystem.scrbl index d5f0f5213a..6b44142129 100644 --- a/pkgs/racket-doc/scribblings/reference/filesystem.scrbl +++ b/pkgs/racket-doc/scribblings/reference/filesystem.scrbl @@ -300,7 +300,8 @@ renamed successfully, the @exnraise[exn:fail:filesystem]. This procedure can be used to move a file/directory to a different directory (on the same filesystem) as well as rename a file/directory within a directory. Unless @racket[exists-ok?] is provided as a true value, -@racket[new] cannot refer to an existing file or directory. Even if +@racket[new] cannot refer to an existing file or directory, but the +check is not atomic with the rename operation on Unix and Mac OS X. Even if @racket[exists-ok?] is true, @racket[new] cannot refer to an existing file when @racket[old] is a directory, and vice versa. diff --git a/racket/src/racket/src/file.c b/racket/src/racket/src/file.c index 4792da8f25..f834767196 100644 --- a/racket/src/racket/src/file.c +++ b/racket/src/racket/src/file.c @@ -4291,9 +4291,17 @@ static Scheme_Object *rename_file(int argc, Scheme_Object **argv) # define MOVE_ERRNO_FORMAT "%E" # else if (!exists_ok && (scheme_file_exists(dest) || scheme_directory_exists(dest))) { - exists_ok = -1; - errno = EEXIST; - goto failed; + /* We use a specialized error message here, because it's not + a system error (e.g., setting `errno` to `EEXIST` would + be a lie). */ + scheme_raise_exn((exists_ok < 0) ? MZEXN_FAIL_FILESYSTEM_EXISTS : MZEXN_FAIL_FILESYSTEM, + "rename-file-or-directory: cannot rename file or directory;\n" + " the destination path already exists\n" + " source path: %q\n" + " dest path: %q", + filename_for_error(argv[0]), + filename_for_error(argv[1])); + return NULL; } while (1) { @@ -4305,9 +4313,6 @@ static Scheme_Object *rename_file(int argc, Scheme_Object **argv) # define MOVE_ERRNO_FORMAT "%e" # endif -#ifndef DOS_FILE_SYSTEM -failed: -#endif scheme_raise_exn((exists_ok < 0) ? MZEXN_FAIL_FILESYSTEM_EXISTS : MZEXN_FAIL_FILESYSTEM, "rename-file-or-directory: cannot rename file or directory\n" " source path: %q\n"