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

Respect symlinks when reading static mocks #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vasvf
Copy link

@vasvf vasvf commented Nov 9, 2021

There was no option to save&repeat redirects in static mocks.

I suggested to make them with symbolic links from file to file.

The problem in current implementation that Vapor follows symlink when reading content of the file, but sets "content-length" header to symlink size. So, we always have incomplete response.

So I decided to check if the file is symlink and then follow it

if fileExists(atPath: symLinkDestination) {
return symLinkDestination
}
let basePath = (path as NSString).deletingLastPathComponent as NSString
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't understand why the last component of the path is being removed

Comment on lines 78 to 79
let basePath = (path as NSString).deletingLastPathComponent as NSString
let symlinkFullPath = basePath.appendingPathComponent(symLinkDestination)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please explain why do we need these lines of code?

Copy link
Author

Choose a reason for hiding this comment

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

It is used when symlink contains relative link to another file. So we reconstruct full path from current symlink path + relative path from symlink

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants