bun icon indicating copy to clipboard operation
bun copied to clipboard

`bun patch` fails with EACCES Permission denied mkdir() when adding new files in nested directory

Open shaunek-hero opened this issue 1 year ago • 5 comments
trafficstars

What version of Bun is running?

1.1.21+70ca2b76c

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

Add any package that has multiple levels of directories, this specific test is with the typescript package. Add a random file to any existing directory in the package that is two levels deep.

bun add typescript
bun patch typescript
# ADD a file in any directory that is child directory of typescript/lib, contents can be anything.
vim node_modules/typescript/lib/es/test.txt
bun patch --commit 'node_modules/typescript'

What is the expected behavior?

After running the bun patch --commit command there should be no error, and the file that was created (ie node_modules/typescript/lib/es/test.txt) should be in place.

What do you see instead?

Shell output is like this:

bun patch v1.1.21 (70ca2b76)
error: failed applying patch file: EACCES: lib/es: Permission denied (mkdir())

Checked 8 installs across 10 packages (no changes) [586.00ms]
error: failed to apply patchfile (patches/[email protected])

It did successfully edit the package.json file and it created this patch file:

diff --git a/node_modules/typescript/lib/es/test.txt b/lib/es/test.txt
new file mode 100644
index 0000000000000000000000000000000000000000..cca7f3bea8af2ec95ec0f2ca6331f9437d515919
--- /dev/null
+++ b/lib/es/test.txt
@@ -0,0 +1,2 @@
+This is in the lib/es dir
+

However, when it attempts to apply the patch file it fails. Repeated attempts to delete the package and run bun install result in the same error: failed applying patch file: EACCES: lib/es: Permission denied (mkdir()) error.

Additional information

When I try to add a file to the root of the package (ie, node_modules/typescript/) or to a subdirectory (ie, node_modules/typescript/lib) it seems to work just fine. This only seems to arise when the file is being added to a directory multiple levels deep. Note that editing files that are multiple levels deep works fine as well, it is only when creating a new file.

I've replicated this problem on a couple of different packages so far. My actual target package is called qbo and interestingly on that package I am able to add a file within the node_modules/qbo/src/entities/ dir, but I cannot add any files to the node_modules/qbo/dist/entities dir nor can I add to the node_modules/qbo/dist/lib dir.

A couple additional notes:

  1. I tried this same package edit with pnpm patch and it worked without a problem.
  2. I took the patch file that bun created and I and applied it "manually" with patch -p1 < [email protected] and that worked without a problem.

shaunek-hero avatar Aug 15 '24 21:08 shaunek-hero

Potentially Related: #12882

KilianB avatar Aug 16 '24 14:08 KilianB

Using v1.1.25 on MacOS 14.5, I patched a few files in the dist/lib/builder folder of a package and then received an error when committing the patch:

error: failed applying patch file: EACCES: dist/lib/builder: Permission denied (mkdir())

It created the patch successfully. The error happens when trying to apply the patch. It seems to be doing something in the cwd. It added a dist folder in my top-level folder. Running ls on that folder gives an error:

% ls dist
ls: fts_read: Permission denied

It created the folder with 644 permissions instead of 755. If I chmod 755 dist and then run bun i again, it fails again with the same error. But now I have a dist/lib folder with 644 permissions. If I jump ahead and create all of the folders that were modified in the package in my project's top-level cwd with proper 755 permissions and run bun i, the patch is applied without error. I can then delete the dist folder and bun i continues to run without error due to having cached the patched package.

rmarscher avatar Aug 21 '24 18:08 rmarscher

Interesting @rmarscher. I tried out your steps and replicated.

I guess a difference in your use case vs mine is that in my case the package already had a dist/some-dir directory and bun patch commit wouldn't let me create any files in that dir (although I could edit files in the same dir), and in your case the package didn't even have a dist directory to start with and weirdly bun patch commit tried to create directories within your project directory instead of in the package itself. Seems like these could be related but could be slightly different bugs I suppose?

shaunek-hero avatar Aug 22 '24 17:08 shaunek-hero

Still seeing this on MacOS with bun version 1.1.27-canary.62

whistlecube avatar Sep 02 '24 03:09 whistlecube

Also seeing this on 1.1.30

erickreutz avatar Oct 16 '24 23:10 erickreutz

I'm seeing this also with bun v1.1.34. I'm attempting to migrate a large react-native monorepo from Yarn Classic to bun, and unfortunately, this is likely to be a blocker.

jasons42 avatar Nov 14 '24 23:11 jasons42

Running into this as well.

Our current workaround has been to patch patch-package so it doesn't use yarn.. though it would be desirable to not have to do this.

ruiconti avatar Jan 13 '25 23:01 ruiconti

@Jarred-Sumner can we get this in 1.2?

erickreutz avatar Jan 14 '25 00:01 erickreutz

seems like it's working since 1.2.1 for me try it out.

EbrahimTahernejad avatar Feb 02 '25 14:02 EbrahimTahernejad

using bun 1.2.2 and still having the issue when i try to patch expo package like hirbod issue

wcastand avatar Feb 19 '25 21:02 wcastand

Just happened to me on Bun 1.2.4, on both Arch Linux and macOS 15.1.1 attempting to patch @capacitor/push-notifications's ios/Sources/PushNotificationsPlugin/PushNotificationsHandler.swift

ThatOneCalculator avatar Mar 10 '25 01:03 ThatOneCalculator

Any movement on this?

LucyEgan avatar Mar 31 '25 11:03 LucyEgan

On macOS specifically, this error (EACCES: Permission denied (mkdir())) can also occur when the diff includes changes to the much-loathed .DS_Store file (which it will if you happened to open any of the relevant folders in Finder while making your edits). Removing the .DS_Store portion from the diff resolves the issue.

diff --git a/node_modules/next/dist/client/.DS_Store b/dist/client/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..dbd07c1a1c1d289c1b490405a326e8a55ae29325
Binary files /dev/null and b/dist/client/.DS_Store differ

bun patch --commit should probably ignore .DS_Store altogether.

agurtovoy avatar Apr 25 '25 19:04 agurtovoy

bump

LucyEgan avatar May 12 '25 13:05 LucyEgan

Still seeing this on OS: macOS 15.5 bun: 1.1.43

algoORgoal avatar Jun 10 '25 11:06 algoORgoal

@zackradisic Can you take a look at this issue? Thank you.

algoORgoal avatar Jun 10 '25 11:06 algoORgoal

Just confirming that https://github.com/oven-sh/bun/issues/13330#issuecomment-2831317868 also fixed the patch for me.

tylerexmg avatar Jul 01 '25 14:07 tylerexmg

there is no .DS_Store patch and still not working OS: macOS 15.5 bun: 1.2.18

lewando54 avatar Jul 09 '25 14:07 lewando54

Is there any workaround or update on this?

JustJoostNL avatar Sep 26 '25 15:09 JustJoostNL

Still an issue in

bun: 1.2.20

xenonwellz avatar Oct 13 '25 16:10 xenonwellz

bun patch v1.3.0 (b0a6feca)
error: failed applying patch file: EACCES: Permission denied (mkdir())
error: failed to apply patchfile (patches/[email protected])

wsl2

badalsaibo avatar Oct 17 '25 16:10 badalsaibo

still an issue in bun 1.3.1 on macos

jakevollkommer avatar Oct 31 '25 15:10 jakevollkommer