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

[Windows] fs.copy error with {preserveTimestamps} #478

Closed
laggingreflex opened this issue Aug 17, 2017 · 7 comments
Closed

[Windows] fs.copy error with {preserveTimestamps} #478

laggingreflex opened this issue Aug 17, 2017 · 7 comments

Comments

@laggingreflex
Copy link

laggingreflex commented Aug 17, 2017

fs.copy(src, dest, {preserveTimestamps: true}) fails on Windows with error:

EPERM: operation not permitted, open 'D:...(dest)'

The error occurs in this part of the code:

Edit: Correction : https://github.com/jprichardson/node-fs-extra/blame/master/lib/copy/ncp.js#L113

https://github.com/jprichardson/node-fs-extra/blame/master/lib/copy/ncp.js#L116

        if (preserveTimestamps) {
          utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
            if (err) return onError(err) <<
            return doneOne()
          })

I forked the library and these 2 tests are also failing:

2 failing

  1) copy > modification option > when modified option is turned on should have the same timestamps on copy:

      Uncaught AssertionError [ERR_ASSERTION]: 1502926785048 === 1502926785000
      + expected - actual

      -1502926785048
      +1502926785000

      at lib\copy\__tests__\copy-preserve-time.test.js:64:20
      at Array.forEach (<anonymous>)
      at copy (lib\copy\__tests__\copy-preserve-time.test.js:46:17)
      at doneOne (lib\copy\ncp.js:228:16)
      at lib\copy\ncp.js:118:20
      at fs.close.closeErr (lib\util\utimes.js:61:23)
      at node_modules\graceful-fs\graceful-fs.js:43:10
      at FSReqWrap.oncomplete (fs.js:135:15)

  2) copySync > modification option > when modified option is turned on should have the same timestamps on copy:

      AssertionError [ERR_ASSERTION]: 1502926785030 === 1502926785000
      + expected - actual

      -1502926785030
      +1502926785000

      at lib\copy-sync\__tests__\copy-sync-preserve-time.test.js:56:20
      at Array.forEach (<anonymous>)
      at Context.it (lib\copy-sync\__tests__\copy-sync-preserve-time.test.js:40:15)
@RyanZim
Copy link
Collaborator

RyanZim commented Aug 17, 2017

@laggingreflex Are you on 32-bit windows?

@laggingreflex
Copy link
Author

64-bit, Window 10

@laggingreflex
Copy link
Author

laggingreflex commented Aug 17, 2017

Expanding on the utimes.utimesMillis the error comes from here:

https://github.com/jprichardson/node-fs-extra/blame/a061b2507ccdff474a80172c2f5db637bfa53905/lib/util/utimes.js#L55

  fs.open(path, 'r+', (err, fd) => { // <<< 
    if (err) return callback(err)
    fs.futimes(fd, atime, mtime, futimesErr => {
      fs.close(fd, closeErr => {
        if (callback) callback(futimesErr || closeErr)
      })
    })
  })

If I replace it with just this it fixes the issue for me:

  fs.utimes(path, atime, mtime, futimesErr => {
    if (callback) callback(futimesErr)
  })

But the tests still don't pass. Using fs.utimes vs. fs.open>fs.futimes>fs.close seems to be required for millisecond precision and it's discussed here #141 (comment)

@laggingreflex
Copy link
Author

laggingreflex commented Aug 17, 2017

Also interesting that the error doesn't occur when running the tests, but they still fail.

The tests fail with the same result:

  -1502926785048
  +1502926785000

Is this due to that millisecond precision? And does Windows actually support millisecond precision?

@laggingreflex
Copy link
Author

laggingreflex commented Aug 17, 2017

I found out in my case the issue was that the destination file was set to "read only".

I think these might be two separate issues.

  • Tests failing due to millisecond issue

  • In my issue the original file (src) has read-only attribute checked, so when fs.copy copies the file it copies and sets that attribute as well (with fs.chmod *) and so sets the read-only attribute. Then when it wants to change the access/modified time it cannot open the file for editing.

* edit: it actually creates the file with the said mode

var writeStream = fs.createWriteStream(target, { mode: file.mode })

@laggingreflex
Copy link
Author

#479 fixes my issue.

@RyanZim
Copy link
Collaborator

RyanZim commented Feb 5, 2018

v5 significantly rewrote copy(), assuming this is fixed.

@RyanZim RyanZim closed this as completed Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants