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

Only delete file if it exists #1177

Merged
merged 2 commits into from
Apr 2, 2020
Merged

Only delete file if it exists #1177

merged 2 commits into from
Apr 2, 2020

Conversation

pepicrft
Copy link
Contributor

@pepicrft pepicrft commented Apr 1, 2020

Short description 📝

While using Tuist, I got this error that indicates that we are trying to delete files even if they don't exist:

We received an error that we couldn't handle:
    - Localized description: “contents.xcworkspacedata” couldn’t be removed.
    - Error: Error Domain=NSCocoaErrorDomain Code=4 "“contents.xcworkspacedata” couldn’t be removed." UserInfo={NSUserStringVariant=(
    Remove
), NSFilePath=/Users/pepibumur/src/github.com/tuist/microfeatures-example/Projects/uFeatures/uFeatures.xcodeproj/project.xcworkspace/contents.xcworkspacedata, NSUnderlyingError=0x7fb643d31b90 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}"

To prevent that from happening, I extended the delete method from FileHandler to do a check before deleting the file. This doesn't prevent race conditions that might happen if we delete files from multiple threads, but at least should minimize the occurrences.

@pepicrft pepicrft requested a review from a team April 1, 2020 16:42
@pepicrft pepicrft self-assigned this Apr 1, 2020
@pepicrft pepicrft requested review from marciniwanicki and removed request for a team April 1, 2020 16:42
@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #1177 into master will increase coverage by 0.54%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1177      +/-   ##
==========================================
+ Coverage   76.88%   77.42%   +0.54%     
==========================================
  Files         273      273              
  Lines        9620     9621       +1     
==========================================
+ Hits         7396     7449      +53     
+ Misses       2224     2172      -52     
Impacted Files Coverage Δ
Sources/TuistSupport/Utils/FileHandler.swift 75.22% <100.00%> (+0.22%) ⬆️
Sources/TuistKit/Commands/InitCommand.swift 55.06% <0.00%> (+5.69%) ⬆️
Sources/TuistSupport/System/System.swift 80.71% <0.00%> (+5.71%) ⬆️
Sources/TuistKit/Commands/LintCommand.swift 75.86% <0.00%> (+6.89%) ⬆️
Sources/TuistKit/Commands/ScaffoldCommand.swift 87.61% <0.00%> (+7.07%) ⬆️
Sources/TuistSigning/SigningCipher.swift 84.70% <0.00%> (+9.41%) ⬆️
Sources/TuistSupport/Xcode/XcodeController.swift 86.95% <0.00%> (+21.73%) ⬆️
Sources/TuistCore/Graph/Nodes/SDKNode.swift 100.00% <0.00%> (+28.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65c7f26...5d53489. Read the comment docs.

@pepicrft pepicrft merged commit ab91a63 into master Apr 2, 2020
@pepicrft pepicrft deleted the remove-file-if-exists branch April 2, 2020 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant