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(Config Schema): Safe generation of standalone AJV validator #10680
Conversation
Codecov Report
@@ Coverage Diff @@
## main #10680 +/- ##
=======================================
Coverage 86.42% 86.42%
=======================================
Files 300 300
Lines 12398 12402 +4
=======================================
+ Hits 10715 10719 +4
Misses 1683 1683
Continue to review full report at Codecov.
|
await fs.promises.writeFile(cachePath, moduleCode); | ||
|
||
const tmpCachePath = path.resolve(getTmpDirPath(), filename); | ||
await fse.outputFile(tmpCachePath, moduleCode); |
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 cleaner to follow same approach as in some other places as:
- Get process-specific tmpdir via
process-utils/tmpdir
- Write file with regular
fsp.writeFile
to it - Safely move a file
We do it when handling deprecation report:
serverless/lib/utils/log-deprecation.js
Lines 141 to 147 in 906f42f
const tmpHealthStatusFilename = path.resolve(await resolveTmpdir(), 'health-status'); | |
await Promise.all([ | |
fse.ensureDir(path.dirname(healthStatusFilename)), | |
fsp.writeFile(tmpHealthStatusFilename, healthStatus.join('\n')), | |
]); | |
await safeMoveFile(tmpHealthStatusFilename, healthStatusFilename); |
ensureDir
)
da0ed42
to
3ef2e80
Compare
3ef2e80
to
4ef79d5
Compare
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.
Looks great 👍
I was encountering this bug when trying to upgrade to v3, thanks for solving it!!! |
Sorry for the trouble @perrin4869 - hopefully this fix will address this problem 👍 |
As noticed by @medikoo, current implementation of saving the file might not be safe and prone to race conditions.
Addresses: #10679