Skip to content

Commit

Permalink
fix: normalize zip file paths before comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Oct 20, 2023
1 parent 63180e6 commit c47ad10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
### Bug Fixes

## [9.7.27](https://github.com/forcedotcom/source-deploy-retrieve/compare/9.7.26...9.7.27) (2023-10-17)

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ export class MetadataApiRetrieve extends MetadataTransfer<
if (this.options.unzip) {
const zip = await JSZip.loadAsync(zipFileContents, { base64: true, createFolders: true });
const extractPath = path.join(this.options.output, path.parse(name).name);
fs.mkdirSync(extractPath);
fs.mkdirSync(extractPath, { recursive: true });
for (const filePath of Object.keys(zip.files)) {
const zipObj = zip.file(filePath);
if (!zipObj || zipObj?.dir) {
fs.mkdirSync(path.join(extractPath, filePath));
fs.mkdirSync(path.join(extractPath, filePath), { recursive: true });
} else {
// eslint-disable-next-line no-await-in-loop
const content = await zipObj?.async('nodebuffer');
Expand Down
8 changes: 5 additions & 3 deletions src/resolve/treeContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable class-methods-use-this */
import { join, dirname, basename, sep } from 'path';
import { join, dirname, basename, normalize, sep } from 'path';
import { Readable } from 'stream';
import { statSync, existsSync, readdirSync, createReadStream, readFileSync } from 'graceful-fs';
import * as JSZip from 'jszip';
Expand Down Expand Up @@ -191,12 +191,14 @@ export class ZipTreeContainer extends TreeContainer {
}

// Finds a matching entry in the zip by first comparing basenames, then dirnames.
// Note that zip files always use forward slash separators, so paths within the
// zip files are normalized for the OS file system before comparing.
private match(fsPath: string): string | undefined {
const fsPathBasename = basename(fsPath);
const fsPathDirname = dirname(fsPath);
return Object.keys(this.zip.files).find((f) => {
if (basename(f) === fsPathBasename || fsPath === '.') {
return dirname(f) === fsPathDirname;
if (normalize(basename(f)) === fsPathBasename || fsPath === '.') {
return normalize(dirname(f)) === fsPathDirname;
}
});
}
Expand Down

2 comments on commit c47ad10

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c47ad10 Previous: 63180e6 Ratio
eda-componentSetCreate-linux 365 ms 335 ms 1.09
eda-sourceToMdapi-linux 7894 ms 7088 ms 1.11
eda-sourceToZip-linux 6908 ms 5909 ms 1.17
eda-mdapiToSource-linux 5307 ms 4642 ms 1.14
lotsOfClasses-componentSetCreate-linux 824 ms 692 ms 1.19
lotsOfClasses-sourceToMdapi-linux 9949 ms 10426 ms 0.95
lotsOfClasses-sourceToZip-linux 9381 ms 8614 ms 1.09
lotsOfClasses-mdapiToSource-linux 6455 ms 5735 ms 1.13
lotsOfClassesOneDir-componentSetCreate-linux 1105 ms 1022 ms 1.08
lotsOfClassesOneDir-sourceToMdapi-linux 16427 ms 14566 ms 1.13
lotsOfClassesOneDir-sourceToZip-linux 16244 ms 14141 ms 1.15
lotsOfClassesOneDir-mdapiToSource-linux 11219 ms 10121 ms 1.11

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c47ad10 Previous: 63180e6 Ratio
eda-componentSetCreate-win32 860 ms 475 ms 1.81
eda-sourceToMdapi-win32 11683 ms 9156 ms 1.28
eda-sourceToZip-win32 7515 ms 6325 ms 1.19
eda-mdapiToSource-win32 11930 ms 7768 ms 1.54
lotsOfClasses-componentSetCreate-win32 1933 ms 1039 ms 1.86
lotsOfClasses-sourceToMdapi-win32 21466 ms 14496 ms 1.48
lotsOfClasses-sourceToZip-win32 11996 ms 9331 ms 1.29
lotsOfClasses-mdapiToSource-win32 14990 ms 9810 ms 1.53
lotsOfClassesOneDir-componentSetCreate-win32 3281 ms 1875 ms 1.75
lotsOfClassesOneDir-sourceToMdapi-win32 33659 ms 22986 ms 1.46
lotsOfClassesOneDir-sourceToZip-win32 19668 ms 16302 ms 1.21
lotsOfClassesOneDir-mdapiToSource-win32 27500 ms 17214 ms 1.60

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.