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: ensure directories are created before writing files #816

Merged
merged 1 commit into from Nov 17, 2021

Conversation

eduardoboucas
Copy link
Member

- Summary

When using archiveFormat: "none", any files in rewrites are written to disk using writeFile. When doing this, we must ensure that the directory structure exists prior to the write operation. This PR addresses that.

- Test plan

Added a new test.

- A picture of a cute animal (not mandatory but encouraged)

749dc9dfe2559f53aa1e466a9af3c609

@eduardoboucas eduardoboucas added the type: bug code to address defects in shipped code label Nov 17, 2021
@@ -86,6 +88,16 @@ const resolveFunctionsDirectories = (input: string | string[]) => {
return absoluteDirectories
}

const mkdirAndWriteFile: typeof pWriteFile = async (path, ...params) => {
if (typeof path === 'string') {
Copy link
Member Author

Choose a reason for hiding this comment

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

Checking that path is a string because it can also be a file descriptor.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is a file descriptor, shouldn't pWriteFile() be used instead of mkdirAndWriteFile() then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely, but we still need to account for the possibility that someone decides to use mkdirAndWriteFile with a file descriptor. If nothing else, TypeScript forces us to have this check since we're setting mkdirAndWriteFile to have the same type as pWriteFile.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ehmicky ehmicky left a comment

Choose a reason for hiding this comment

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

👍

@eduardoboucas eduardoboucas merged commit 8ea63dd into main Nov 17, 2021
@eduardoboucas eduardoboucas deleted the fix/nft-archiveformat-none branch November 17, 2021 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants