Repository navigation
Keep Storage emulator object keys literal instead of path.join-normalizing them #11307
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
base: main
Are you sure you want to change the base?
Changes from all commits
7857a95
78daee2
23adc1a
efb2cbc
7496b1f
e678998
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -522,8 +522,14 @@ export class StorageLayer { | |||||||||||||||||||||||||||
| return metadata; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * Returns the key an object is stored under. Object names are literal in Cloud Storage, so the | ||||||||||||||||||||||||||||
| * key must keep the name as is: `path.join` would collapse `.` and `..` segments (and, on | ||||||||||||||||||||||||||||
| * Windows, treat `\` as a separator), letting two different names share one stored object. | ||||||||||||||||||||||||||||
| * Bucket names cannot contain `/`, so the key is unique per bucket and object. | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| private path(bucket: string, object: string): string { | ||||||||||||||||||||||||||||
| return path.join(bucket, object); | ||||||||||||||||||||||||||||
| return `${bucket}/${object}`; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public get dirPath(): string { | ||||||||||||||||||||||||||||
|
|
@@ -628,11 +634,11 @@ export class StorageLayer { | |||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Exports written on Windows by older versions stored object names with `\` separators. | ||||||||||||||||||||||||||||
| // Such a name is recognized by its first separator being `\`. | ||||||||||||||||||||||||||||
| let fileName = metadata.name; | ||||||||||||||||||||||||||||
| const objectNameSep = getPathSep(fileName); | ||||||||||||||||||||||||||||
| // Replace all file separators with that of current platform for compatibility | ||||||||||||||||||||||||||||
| if (fileName !== path.sep) { | ||||||||||||||||||||||||||||
| fileName = fileName.split(objectNameSep).join(path.sep); | ||||||||||||||||||||||||||||
| if (/[/\\]/.exec(fileName)?.[0] === "\\") { | ||||||||||||||||||||||||||||
| fileName = fileName.split("\\").join("/"); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
639
to
642
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The helper function
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const filepath = this.path(metadata.bucket, fileName); | ||||||||||||||||||||||||||||
|
|
@@ -654,10 +660,3 @@ export class StorageLayer { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** Returns file separator used in given path, either '\\' or '/'. */ | ||||||||||||||||||||||||||||
| function getPathSep(decodedPath: string): string { | ||||||||||||||||||||||||||||
| // Checks for the first matching file separator | ||||||||||||||||||||||||||||
| const firstSepIndex = decodedPath.search(/[/|\\\\]/g); | ||||||||||||||||||||||||||||
| return decodedPath[firstSepIndex]; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
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.
The temporary directories created with
mkdtempSyncare never cleaned up, which can clutter the system's temporary folder over time. Wrapping the test logic in atry...finallyblock ensures that these directories are always deleted, even if the test assertions fail.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, done in 78daee2: the export/import test now creates both temp directories up front and deletes them in a
finally, so they get cleaned up even when an assertion fails. The new|import test cleans up its export directory the same way.