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

Remove directory symlinks before starting upload #103

Merged
merged 1 commit into from
Jul 27, 2020
Merged

Conversation

konradpabjan
Copy link
Collaborator

@konradpabjan konradpabjan commented Jul 27, 2020

Overview

Resolves #76

The root cause was that fs.lstat was used instead of fs.stat. Certain paths should have been omitted from the list of files to upload and this ensures directories correctly get identified before an upload begins.

fs.lstat will always return false when isDirectory is called if the filePath is a symbolic link. This can cause problems down the line when fs.createReadStream is called inside @actions/artifact during upload.

Testing

https://github.com/konradpabjan/macos-eisdir/runs/914682769?check_suite_focus=true

I used a minimal repo that a user created as part of #76
In a earlier failed run, you can see that the problematic file is a symlink: https://github.com/konradpabjan/macos-eisdir/runs/914415784?check_suite_focus=true#step:5:81

With the symlink present i first tried lstat() then realPath() and then isDirectory() before that is able to correctly say if that is a directory. A single call with stat() will correctly determine if the path is a directory. In addition, even with the full real path, I tried doing fs.createReadStream and that would fail with the same EISDIR error so the symlink/directory should never be uploaded to begin with

if (!lstatSync(searchResult).isDirectory()) {
const fileStats = await stats(searchResult)
// isDirectory() returns false for symlinks if using fs.lstat(), make sure to use fs.stat() instead
if (!fileStats.isDirectory()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test with a symlink loop here? What would happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Loops would not be included as part of the rawSearchResults. @actions/glob checks beforehand for broken symlinks and cycles and removes them.

We filter out directories after @actions/glob has finished searching

@yacaovsnc yacaovsnc self-requested a review July 27, 2020 13:35
@konradpabjan konradpabjan merged commit 5f948bc into main Jul 27, 2020
@konradpabjan konradpabjan deleted the symlink-fixes branch July 27, 2020 13:41
aguibert pushed a commit to aguibert/upload-artifact that referenced this pull request Oct 20, 2020
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.

macos: EISDIR: illegal operation on a directory
2 participants