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(GITHUB-6525-5172): Rewrite copyDirContentsSyncAllow to call fs-extra::copySync() on the directories instead of calling it on the files to copy individually #6526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephaneseng great thanks for that PR!
Relying on copySync
is good call, however ignoring symlinks feels as a breaking change. Currently I believe they're resolved as files and copied so in destination we have files. While after taking this change in, they'll be missing.
Are we sure it wouldn't break existing scenarios?
lib/utils/fs/copyDirContentsSync.js
Outdated
noLinks: false, | ||
}, | ||
opts | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move it to function signature as e.g. { noLinks = false } = {}
? I think it'll be more readable (and less verbose) that way
lib/utils/fs/copyDirContentsSync.js
Outdated
dereference: true, | ||
}; | ||
if (options.noLinks) { | ||
copySyncOptions.filter = isNotSymbolicLink; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll be nicer to keep it within copySyncOptions
definition as e.g.
const copySyncOptions = {
dereference: true,
filter: options.noLinks ? isNotSymbolicLink : null
};
…tra::copySync() on the directories instead of calling it on the files to copy individually. The main motivation behind these changes is to rely on https://github.com/jprichardson/node-fs-extra/blob/8.1.0/docs/copy-sync.md as much as possible in order to avoid having to do the `fullFilePath.replace(srcDir, '')` operation because this operation can be error-prone. Doing so fixes the following issues because the user-submitted file paths are now correctly interpreted by fs-extra, closing both serverless#6525 and serverless#5172.
5be54a0
to
5952712
Compare
Thanks for your review @medikoo. Concerning your question about the eventual breaking changes brought by these changes: The current behavior of We can then observe the following behavior, on master: 1.a. When called with no options, or with
The symbolic link copied is indeed dereferenced. 1.b. When called with
The symbolic link is already ignored. This is because:
Furthermore, by executing these tests on this PR branch, we can observe the same behavior than the current one: 2.a. When called with no options, or with
The symbolic link copied is also dereferenced. 2.b. When called with
The symbolic link is also ignored. Thus, because the results of calls to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephaneseng thanks for clarification. Indeed we're safe here, and it looks really good!
I really appreciate an extra tests that were introduced for that.
I'm taking this in, it'll be published tomorrow with v1.50.0
What did you implement
The main motivation behind these changes is to rely on https://github.com/jprichardson/node-fs-extra/blob/8.1.0/docs/copy-sync.md as much as possible in order to avoid having to do the
fullFilePath.replace(srcDir, '')
operation because this operation can be error-prone.Doing so fixes the following issues because the user-submitted file paths are now correctly interpreted by fs-extra:
Fixes #6525
Fixes #5172
How did you implement it
About
noLinks
copyDirContentsSync()
is called only once with a third parameter.This parameter is set to
{ noLinks: true }
at https://github.com/serverless/serverless/blob/v1.49.0/lib/plugins/create/create.js#L163.Furthermore,
noLinks
is also the only option accepted bywalkDirSync
, as seen in https://github.com/serverless/serverless/blob/v1.49.0/lib/utils/fs/walkDirSync.js#L7.Thus this
noLinks
option had to be kept in this new implementation, preventing the copy of symbolic links if it is set totrue
.About
dereference
In the previous implementation, when copied, symbolic links were always dereferenced.
This means that, when the following folder was copied:
This resulting file structure was created, with
my-symbolic-link-to-serverless-state.json
no longer being a symbolic link:The reason why that is the case is not obvious when reading https://github.com/jprichardson/node-fs-extra/blob/0.30.0/lib/copy-sync/copy-sync.js.
Even though the
dereference
option was always left to itsfalse
default value, the symbolic links were always dereferenced in our case because:copySync()
dereference
option is ignored bycopySync()
, as shown in https://github.com/jprichardson/node-fs-extra/blob/0.30.0/lib/copy-sync/copy-sync.js#L21How can we verify it
For #6525:
For #5172: Specifically in a Windows environment:
Todos
Note: Run
npm run test-ci
to run all validation checks on proposed changesValidate via
npm test
Validate via
npm run lint-updated
Note: Some reported issues can be automatically fixed by running
npm run lint:fix
Validate via
npm run prettier-check-updated
Note: All reported issues can be automatically fixed by running
npm run prettify-updated
Is this ready for review?: YES
Is it a breaking change?: NO