Skip to content

Windows: ftruncate to shrink file gives EPERM #3177

Description

@jorangreef

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?

Activity

  1. bnoordhuis commented on Oct 5, 2015

    @bnoordhuis
    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.

  2. added
    questionIssues asking questions about Node.js.
    fsIssues and PRs related to file-system APIs and the fs module.
    windowsIssues and PRs related to the Windows platform.
    on Oct 5, 2015
  3. jorangreef commented on Oct 5, 2015

    @jorangreef
    ContributorAuthor

    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+".

  4. sam-github commented on Oct 8, 2015

    @sam-github
    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.

  5. added
    docIssues and PRs related to Node.js documentation.
    on Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.fsIssues and PRs related to file-system APIs and the fs module.questionIssues asking questions about Node.js.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions