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

carthage copy-frameworks produces "The file couldn’t be saved." error #3056

Closed
adbqpa opened this issue Sep 21, 2020 · 33 comments
Closed

carthage copy-frameworks produces "The file couldn’t be saved." error #3056

adbqpa opened this issue Sep 21, 2020 · 33 comments
Labels

Comments

@adbqpa
Copy link

adbqpa commented Sep 21, 2020

  • carthage install method: [x] .pkg, [x] homebrew, [x] source
  • which carthage:
  • carthage version: 0.36.0
  • xcodebuild -version: Build version 11E801a
  • Are you using --no-build? No
  • Are you using --no-use-binaries? No
  • Are you using --use-submodules? No
  • Are you using --cache-builds? Yes
  • Are you using --new-resolver? No

Actual outcome
Xcode project build fails, because command "carthage copy-frameworks" returns non zero result, with error: "The file couldn’t be saved."
My investigation showed that the problem was a failed attempt to create a temporary directory due to reaching the maximum allowed limit of 1000 temporary directories. I found information about this limit on the forum https://developer.apple.com/forums/thread/128927
The complete error looks like this: Error Domain = NSCocoaErrorDomain Code = 512 "The file couldn’t be saved."
The code in which the error occurs:

public func createTemporaryDirectoryWithTemplate (_ template: String, destinationURL: URL) -> SignalProducer <URL, CarthageError> {
return SignalProducer {[base = self.base] () -> Result <String, CarthageError> in
      let temporaryDirectory: NSString
      do {
        temporaryDirectory = try base.url (
          for: .itemReplacementDirectory,
          in: .userDomainMask,
          appropriateFor: destinationURL,
          create: true
        )
        .path as NSString
      } catch {
>>>>>>> return .failure (.internalError (description: error.localizedDescription)) <<<<<<< error stopping the build here
      }
.............

Expected outcome
Carthage should clean up the created temporary folders at the end of the work in order not to reach this limit, or issue human-readable errors with guidance for further actions, instead of the system error "The file couldn’t be saved."

@Droppix
Copy link

Droppix commented Sep 22, 2020

same error
after some time, i have "The file couldn’t be saved."

/bin/sh -c /Users/xxxx/Library/Developer/Xcode/DerivedData/xxxxx-fmaccoypantpmwcbvalvgebzktwd/Build/Intermediates.noindex/xxxxx.build/Debug-iphonesimulator/xxxx.build/Script-2D6F48152518F1F300CCDBE0.sh

"The file couldn’t be saved.
Command PhaseScriptExecution failed with a nonzero exit code

The contents of Script-2D6F48152518F1F300CCDBE0.sh

#!/bin/sh
# Type a script or drag a script file from your workspace to insert its path.
/usr/local/bin/carthage copy-frameworks

Only one solution for me : Reboot MAC (clean derived data, don't work!)

@adbqpa
Copy link
Author

adbqpa commented Sep 22, 2020

Only one solution for me : Reboot MAC (clean derived data, don't work!)

Clearing DerivedData should not help, the problem is in the $TMPDIR/TemporaryItems folder, hypothetically, it should be cleared when the computer is restarted, which in theory should help, but on my build machine, frequent reboots are not possible

@caobug
Copy link

caobug commented Sep 22, 2020

Add to run scripts

rm -rf ${TMPDIR}/TemporaryItems/*carthage*
/usr/local/bin/carthage copy-frameworks

@PierreBrisorgueil
Copy link

@caobug tempo fix work for me 👍

renep pushed a commit to openbakery/SwiftHamcrestAutolayoutMatchers that referenced this issue Sep 22, 2020
@kokluch
Copy link

kokluch commented Sep 22, 2020

+1

@ryecroft
Copy link

Thanks @caobug. I had to remove the first forward-slash from the command to get it to work:

rm -rf ${TMPDIR}TemporaryItems/*carthage*
/usr/local/bin/carthage copy-frameworks

Otherwise it was resulting in a path like /var/folders/f1/5dssh6dx6rs_c9gbf039djww0000gn/T//TemporaryItems/.

@AlexisQapa
Copy link

I ran into this issue and restarting solved the issue. The proposed fix in the comments didn't worked for me thought (with and without the /)

@maqoo
Copy link

maqoo commented Sep 24, 2020

I started to face this issue today morning and after I deleted all from TemporaryItems directory I was able to build successfully.

@kientux
Copy link

kientux commented Sep 26, 2020

rm -rf ${TMPDIR}TemporaryItems/*carthage*

This command does not work on my machine, I tried to run it on Terminal and it gives Operation not permitted error.
Solution for who doesn't want to restart is to remove those temporary items manually by opening the $TMPDIR in Finder. Run this in Terminal:

open $TMPDIR/TemporaryItems

then just remove all directories created by Carthage (named (A Document Being Saved By carthage))

@stepheng
Copy link

@kientux You can work around it by enabling Full Disk Access for Terminal (or, your build manager if you're using CI with remote machines).

@pjcau
Copy link

pjcau commented Sep 28, 2020

@kientux I had the same issue, so you should enable Xcode App on Full Disk Access.

@norbdev
Copy link

norbdev commented Sep 29, 2020

macOS 10.15.6, Xcode 12.0.1

Only the (Xcode) "Full Disk Access" not working for me, have to add this:

rm -rf ${TMPDIR}TemporaryItems/*carthage*
/usr/local/bin/carthage copy-frameworks

@pjcau
Copy link

pjcau commented Sep 29, 2020

@norbdev I Use this lines
echo "TMPDIR is ${TMPDIR}" rm -rf ${TMPDIR}TemporaryItems/ /usr/local/bin/carthage copy-frameworks

@simonpierreroy
Copy link

At scale on CI machines, the limit is reached pretty fast. Most of my CI machines reached the 1000 limit inside TemporaryItems in a day! But indeed, removing item in "${TMPDIR}TemporaryItems/" will fix it for now. @adbqpa perfectly identified the issues #3056 (comment), thank you.

@nnduc
Copy link

nnduc commented Oct 2, 2020

Add to run scripts

rm -rf ${TMPDIR}/TemporaryItems/*carthage*
/usr/local/bin/carthage copy-frameworks

Thank @caobug . It's work

@Droppix
Copy link

Droppix commented Oct 2, 2020

@norbdev
I have same error, rm -rf ${TMPDIR}/TemporaryItems/*carthage*work only on Terminal, but not in XCode.
Would you have found a solution

@raducanb
Copy link

raducanb commented Oct 2, 2020

@Droppix have you tried enabling full disk access for Xcode?
Screenshot 2020-10-02 at 09 34 25

@Droppix
Copy link

Droppix commented Oct 2, 2020

@raducanb
Sorry but yes, I knew it was checked! Thanks, it's ok, it works!

@SValchyshyn
Copy link

Add to run scripts

rm -rf ${TMPDIR}/TemporaryItems/*carthage*
/usr/local/bin/carthage copy-frameworks

If we do it this way on CI machine, it means fetching and building dependencies each time. Do we have a better approach? @simonpierreroy do you have such a problem?

@tmspzz
Copy link
Member

tmspzz commented Oct 8, 2020

@SValchyshyn you want to delete just *carthage-lipo*

@geoherna
Copy link

Enabling full disk access for Xcode solved this issue for me.

@Johennes
Copy link

Is there any built-in fix for this coming up? If #3047 introduced this, could that change be reverted? As far as I understand #3047 tried to fix a sporadic issue. However, the new issue is deterministic now and impacts all our CI setups.

@aivcec
Copy link

aivcec commented Nov 11, 2020

This happens on my CI machine as well. None of the fixes above work. I have to manually restart the machine.
Xcode 11.7, macOS 10.15.2

@Johennes
Copy link

@jdhealy / @tmspzz any thoughts on reverting #3047? Periodically logging into our CI servers to delete temporary files doesn't sound like a real solution.

@joelfischerr
Copy link

This happens on my CI machine as well. None of the fixes above work. I have to manually restart the machine.

Xcode 11.7, macOS 10.15.2

This looks like it could be caused by a CI runner without proper access rights. Have you checked whether it also has full disk access rights?

@trzeciak
Copy link

If you use TeamCity as the CI, its probably overrides $TMPDIR, therefore I try this workaround as a (Custom script) TeamCity Build Step:

echo 'import Foundation
let ls = Process()
ls.executableURL = URL(fileURLWithPath: "/usr/bin/env")
ls.arguments = ["bash", "-c", "set -x && rm -rfv " + NSTemporaryDirectory() + "TemporaryItems/*carthage*"]
try ls.run()
' | swift

(I haven't found a simpler method to recover $TMPDIR)

@anton-plebanovich
Copy link

This one works in Xcode run scripts:

for i in {1..1000}; do
    dir_name="${TMPDIR}TemporaryItems/(A Document Being Saved By carthage ${i})"
    [ -e "${dir_name}" ] && rm -rf "${dir_name}"
done

@aivcec
Copy link

aivcec commented Dec 2, 2020

Still happens to me and I don't believe its a permission issue.
EDIT: I didn't give permission to the terminal, only to Xcode.

EDIT2: Problems persists even with added permissions

I also see it happen on carthage bootstrap.

@ObjectiveCesar
Copy link

Any news on this one?

@ozgur
Copy link

ozgur commented Dec 20, 2020

rm -rf ${TMPDIR}TemporaryItems/*carthage*

This command does not work on my machine, I tried to run it on Terminal and it gives Operation not permitted error.
Solution for who doesn't want to restart is to remove those temporary items manually by opening the $TMPDIR in Finder. Run this in Terminal:

open $TMPDIR/TemporaryItems

then just remove all directories created by Carthage (named (A Document Being Saved By carthage))

For those who don't want to do that manually, I've written a simple python script in order to navigate around that nasty Operation not permitted error:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import glob
import os
import shutil
import tempfile

if __name__ == "__main__":
    tmpdir = os.path.join(tempfile.gettempdir(), "TemporaryItems")
    for f in glob.glob(f'{tmpdir}/*carthage*/'):
        shutil.rmtree(os.path.join(tmpdir, f), ignore_errors=True)

then on terminal

$ python /path/to/script.py

should clean the folders inside tmp folder created by Carthage.

PS: Don't forget to grant write permission: sudo chmod -R +w "${TMPDIR}"

@clarissaj
Copy link

clarissaj commented Jan 15, 2021

FYI it looks like this issue is fixed in the latest release!! (0.36.1) 🎉🎉🎉🎉

@ObjectiveCesar
Copy link

FYI it looks like this issue is fixed in the latest release!! (0.36.1) 🎉🎉🎉🎉

That would be awesome. I‘ll try to verify that on Monday. Thanks for the heads-up!

@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2022
@stale stale bot closed this as completed Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests