Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

fs.copyFile and snapshot filesystem #420

Closed

Description

@jsonmaur

Trying to copy a file from the snapshot filesystem to the real filesystem results in the following error:
ENOENT: no such file or directory. Seems to happen in all versions after 4.2.4.

Example code that should work:

fs.copyFile(
  path.resolve(__dirname, 'some_file.json'),
  path.resolve(process.cwd(), 'some_new_file.json')
)

Activity

  1. jsonmaur commented on May 14, 2018

    @jsonmaur
    Author

    Using ncp as a temporary workaround since it doesn't rely on the fs.copyFile function.

  2. jdziat commented on Jun 14, 2018

    @jdziat

    Another option that works is to use:

    const fileBuffer = fs.readFileSync(path.resolve(__dirname, 'some_file.json'))
     
    fs.writeFileSync(self.dynLibraryPath, fileBuffer)
  3. AxelTerizaki commented on Jul 9, 2018

    @AxelTerizaki

    I can confirm your little trick worked out for me o/

  4. sqliang commented on Apr 3, 2019

    @sqliang

    Trying to copy a file from the snapshot filesystem to the real filesystem results in the following error:
    ENOENT: no such file or directory. Seems to happen in all versions after 4.2.4.

    Example code that should work:

    fs.copyFile(
      path.resolve(__dirname, 'some_file.json'),
      path.resolve(process.cwd(), 'some_new_file.json')
    )

    Maybe pkg does not kidnap function fs.copyFile. I meet the same issue, and I resolve it by replace copyFile with readFile & writeFile:

    // previously:
    function copyFile(sourcePath, targetPath) {
        generatedFilePaths.push(targetPath);
        fs.copyFileSync(sourcePath, targetPath);
    }
    // now:
    function copyFile(sourcePath, targetPath) {
        generatedFilePaths.push(targetPath);
        const sourceData = fs.readFileSync(sourcePath, ENCODING);
        fs.writeFileSync(targetPath, sourceData, ENCODING);
    }
  5. paulocoghi commented on Apr 18, 2019

    @paulocoghi

    What can we do when using fs-extra?

    I get the same error when calling a fs.copy, but I would not like to manually rewrite it (to be able to apply those workarounds), since there is a lot of things made on fs-extra.

  6. jdziat commented on Apr 18, 2019

    @jdziat

    You need to not use the copy method from the fs-extra package. It must do something with path that pkg intercepts/changes.

  7. paulocoghi commented on Apr 19, 2019

    @paulocoghi

    It seems to be a regression bug, since it worked fine until 4.2.6.

  8. jingsam commented on Dec 24, 2019

    @jingsam

    This issue is still not solved. Any progress on this issue? @igorklopov

  9. jingsam commented on Jul 2, 2020

    @jingsam

    Hi, @igorklopov thanks for your great work. However, this issue is indeed a pain in our application and still not fixed for two years. Do you have any plans to get this issue to be solved, or suggest some work rounds. Many thanks and wish you a good day.

  10. medikoo commented on Jul 2, 2020

    @medikoo
  11. ryanaltair commented on Sep 3, 2020

    @ryanaltair

    Another option that works is to use:

    const fileBuffer = fs.readFileSync(path.resolve(__dirname, 'some_file.json'))
     
    fs.writeFileSync(self.dynLibraryPath, fileBuffer)

    this work with pkg 4.4.9
    with node14

  12. github-actions commented on Apr 20, 2021

    @github-actions

    This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

  13. medikoo commented on Apr 20, 2021

    @medikoo

    .

  14. 3 remaining items

  15. jingsam commented on Sep 26, 2021

    @jingsam

    bump

  16. github-actions commented on Dec 26, 2021

    @github-actions

    This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

  17. paulocoghi commented on Dec 27, 2021

    @paulocoghi

    .

  18. robertsLando commented on Dec 27, 2021

    @robertsLando
    Contributor

    Hi everyone, I use pkg like you for my projects and when I find a bug I try to fix it my self, fixing this is not so difficult as it just require to add a patch like the one specified by @medikoo in prelude/bootstrap.js.

    Please if you use this project help to keep it maintained by contributing to it.

    Thanks

  19. added a commit that references this issue on Jan 17, 2022
    8c1c97c
  20. robertsLando commented on Jan 20, 2022

    @robertsLando
    Contributor

    PR ready to fix this

  21. jdziat commented on Jan 20, 2022

    @jdziat

    @robertsLando I like it, i think the only thing is that it may lead people to not understand context when working with this package. If they inadvertently forget to include a file in the snapshot and it loads a file from the filesystem instead it could cause some issues or in a worst case scenario a vulnerability. I think that's why this hasn't been patched/implemented.

  22. robertsLando commented on Jan 20, 2022

    @robertsLando
    Contributor

    @jdziat IMO the patch should be integrated to bootstrap as lot users are having this issue

  23. jdziat commented on Jan 20, 2022

    @jdziat

    @robertsLando Not disagreeing but you may want to make it possible to turn this off via a flag.

  24. soopermodel commented on Jul 17, 2023

    @soopermodel

    bump

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions