Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different speed of file rename to non-accessible destination on Windows #247

Open
xmedeko opened this issue Apr 4, 2024 · 0 comments
Open

Comments

@xmedeko
Copy link

xmedeko commented Apr 4, 2024

Hello, I'm trying to rename file to a destination folder where the user has no access, rename fails with EPERM error correctly, but when the target file exists, it fails immediately, when the target file does not exists, it fails after 60 sec. E.g. my code:

const util = require('util');
const gfsRename = util.promisify(require('graceful-fs').rename);
(async () => {
  const start = Date.now();
  try {
    await gfsRename("somefile.txt", "c:\\Program Files\\somefile.txt");
  } catch (err) {
    console.log("graceful-fs.rename error in", Date.now() - start, err.message);
  }
})();

Since I have no antivirus which would require to use this rename - retry workaround, I am not able to test if such difference is reasoned or a bug.

I think the problem is in the solution of #98 and commit 90a96bc, see also code

fs.stat(to, function (stater, st) {
IMHO fs.stat result should be checked that target is a directory, too.

Note: to fail fast if AV is blocking the rename, could be possible to open and close target, something like fs.open(src, 'a') ... fs.close(...) ? If so, it may not be part of the library, but could be documented in README.md only, I think.

@xmedeko xmedeko changed the title Different speed of rename fo file to non-accessible destination on Windows Different speed of file rename to non-accessible destination on Windows Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant