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

Fix watcher crashing in package subdirectories #67

Merged
merged 6 commits into from
Jul 25, 2020

Conversation

MaxDesiatov
Copy link
Collaborator

@MaxDesiatov MaxDesiatov commented Jul 23, 2020

Currently, when carton dev is launched in any subdirectory of the package not containing Package.swift it crashes. It's caused by traverseRecursively precondition failing when a non-directory (or non-existent) path is passed to it. I think traverseRecursively can handle non-existing paths well by returning an empty array, and the path itself when it's a file and not a directory. Thus the precondition check is not needed at all.

Non-existent paths were created due to a wrong assumption that the root package directory is always the current directory. This is now fixed by adding a new inferManifestDirectory function, which correctly calculates absolute paths of source directories before passing them to the watcher.

Additionally the watcher code in the TSCBasic code has its own precondition for non-empty path arrays passed to it. To avoid triggering it and staying extra-safe, we check for an empty watcher paths array and avoid watching anything at all.

@MaxDesiatov MaxDesiatov added the bug Something isn't working label Jul 23, 2020
@MaxDesiatov MaxDesiatov marked this pull request as draft July 23, 2020 21:14
@MaxDesiatov MaxDesiatov changed the title Add a proper traverseRecursively error message Fix watcher crashing in package subdirectories Jul 24, 2020
@MaxDesiatov MaxDesiatov marked this pull request as ready for review July 24, 2020 14:34

// `parentDirectory` just returns `self` if it's `root`
cwd = cwd.parentDirectory
} while cwd != root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that AbsolutePath has a property isRoot to check whether it's a root directory.

Suggested change
} while cwd != root
} while !cwd.isRoot

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I initially wasn't sure if this property is public at all.

Co-authored-by: ninjiacoder <ninjiacoder@gmail.com>
@MaxDesiatov MaxDesiatov merged commit db504a0 into main Jul 25, 2020
@MaxDesiatov MaxDesiatov deleted the path-precondition-message branch July 25, 2020 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants