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: ftruncate to shrink file gives EPERM #3177

Closed
jorangreef opened this issue Oct 5, 2015 · 3 comments
Closed

Windows: ftruncate to shrink file gives EPERM #3177

jorangreef opened this issue Oct 5, 2015 · 3 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. question Issues that look for answers. windows Issues and PRs related to the Windows platform.

Comments

@jorangreef
Copy link
Contributor

I have a file with the following stats in a Windows VM:

{"dev":-24039965,"mode":33206,"nlink":1,"uid":0,"gid":0,"rdev":0,"ino":562949953548321,"size":39035842,"atime":"2015-10-03T09:59:32.677Z","mtime":"2015-10-03T10:00:17.241Z","ctime":"2015-10-03T10:00:17.241Z","birthtime":"2015-10-03T09:59:32.677Z"}

Truncating this file using ftruncate from 39035842 to 38839234 byte (to make it smaller) gives EPERM.

Is ftruncate simply not supported at all on Windows? I thought it was only ftruncate to enlarge a file that was not permitted on Windows?

@bnoordhuis
Copy link
Member

/cc @nodejs/platform-windows - I don't know the answer to this question. I thought that as long as you have the appropriate privileges and the file is opened for writing (not appending), you should be able to truncate it in either direction.

@bnoordhuis bnoordhuis added question Issues that look for answers. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels Oct 5, 2015
@jorangreef
Copy link
Contributor Author

Thanks Ben, that was the problem. I had the file opened on Windows using "a+".

On Mac however, ftruncate still works if the file is opened with "a+".

@sam-github
Copy link
Contributor

This behaviour is undocumented in node, and I'd welcome a PR for that, but node doesn't reduce Windows and Unixen to a "lowest common denominator", there are differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. question Issues that look for answers. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

3 participants