-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(s3-assets): cannot publish a file without extension #30597
Conversation
@Mergifyio update |
❌ Mergify doesn't have permission to updateFor security reasons, Mergify can't update this pull request. Try updating locally. |
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.
Thanks for the deep dive!
I wonder if we can simplify this a bit, but apart from that looks good!
private renderStagedPath(sourcePath: string, targetPath: string): string { | ||
// Add a suffix to the asset file name | ||
// because when a file without extension is specified, the source directory name is the same as the staged asset file name. | ||
if (this.hashType === AssetHashType.SOURCE && path.dirname(sourcePath) === targetPath) { |
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.
Does this even on the hashType
? It seems that if dirname(sourcePath) === targetPath
we always have a problem?
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.
Changed the conditional to this.hashType !== AssetHashType.OUTPUT
and added the reason to the comment.
9f5adb5
// Add a suffix to the asset file name | ||
// because when a file without extension is specified, the source directory name is the same as the staged asset file name. | ||
if (this.hashType === AssetHashType.SOURCE && path.dirname(sourcePath) === targetPath) { | ||
targetPath = targetPath + 'noext'; |
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.
targetPath = targetPath + 'noext'; | |
targetPath = targetPath + '_noext'; |
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.
Changed suffix to _noext
.
ecee169
// If the fileName begins with 'asset.', remove it here | ||
// because when a file without extension is added to the manifest, the path.extension() will return an file hash. | ||
// ex) path.extension('asset.dc5ce447844') => 'dc5ce447844' |
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.
This comment seems to not match what the code is doing? Or does it?
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.
Deleted comment.
I forgot to delete it.
69889ec
@rix0rrr |
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.
<3
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #30471
Reason for this change
Publishing a file with no extension using the
Asset
class withBundlingOutput.SINGLE_FILE
andAssetHashType.SOURCE
(default), as shown below, will result in an errorfail: EISDIR: illegal operation on a directory, read
, and publishing will fail.This is because the path in
*.asset.json
is different from the actual file path.The
*.asset.json
expects the file to be inasset.bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0
, but when I check thecdk.out
directory, I see thatasset.bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0
is a directory, not a file.If I change it to a file with an extension, as shown below, I see that the file with the extension is staged under
cdk.out
dir, and the asset is published successfully.cdk.out ├── SampleStack.assets.json ├── SampleStack.template.json ├── asset.dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8 │ └── main.bin ├── asset.dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8.bin # !! staged file here !! ├── cdk.out ├── manifest.json └── tree.json
Files without extensions must be staged correctly in order to be published correctly.
Description of changes
The directory to write the bundling output is usually
cdk.out/asset.{asset hash}
.If the extension exists, it will be renamed from
cdk.out/asset.{asset hash}/{asset file name}
tocdk.out/{asset hash}.{asset file extension}
.aws-cdk/packages/aws-cdk-lib/core/lib/asset-staging.ts
Line 392 in c826d8f
If the extension does not exist, the file name
cdk.out/asset.{asset hash}
(without extension) will be the same as the directory where bundling output is written.Therefore, the file is already considered staged and will not be staged correctly.
aws-cdk/packages/aws-cdk-lib/core/lib/asset-staging.ts
Line 383 in c826d8f
Therefore, in such cases, I fix to change the file name by adding a suffix such as
noext
after the file name so that the file is correctly renamed.Description of how you validated changes
unit tests and integ test.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license