Skip to content

Commit

Permalink
perf(fslib): skip symlink logic if the zip file has no symlinks (#1535)
Browse files Browse the repository at this point in the history
* perf(fslib): skip symlink logic if no symlinks exists

* chore: versions
  • Loading branch information
merceyz committed Jul 5, 2020
1 parent 3c27c96 commit f6f7788
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 45 deletions.
45 changes: 28 additions & 17 deletions .pnp.js

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions .yarn/versions/b76ae547.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
releases:
"@yarnpkg/cli": prerelease
"@yarnpkg/fslib": prerelease
"@yarnpkg/libzip": prerelease
"@yarnpkg/plugin-pnp": prerelease
"@yarnpkg/pnp": prerelease

declined:
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/json-proxy"
- "@yarnpkg/pnpify"
- "@yarnpkg/shell"
24 changes: 20 additions & 4 deletions packages/yarnpkg-fslib/sources/ZipFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export class ZipFS extends BasePortableFakeFS {
private readonly listings: Map<PortablePath, Set<Filename>> = new Map();
private readonly entries: Map<PortablePath, number> = new Map();

private symlinkCount: number

private readonly fds: Map<number, {cursor: number, p: PortablePath}> = new Map();
private nextFd: number = 0;

Expand Down Expand Up @@ -273,6 +275,8 @@ export class ZipFS extends BasePortableFakeFS {
}
}

this.symlinkCount = this.libzip.ext.countSymlinks(this.zip);

this.ready = true;
}

Expand Down Expand Up @@ -545,6 +549,14 @@ export class ZipFS extends BasePortableFakeFS {
}

existsSync(p: PortablePath): boolean {
if (!this.ready)
throw errors.EBUSY(`archive closed, existsSync '${p}'`);

if (this.symlinkCount === 0) {
const resolvedP = ppath.resolve(PortablePath.root,p);
return this.entries.has(resolvedP) || this.listings.has(resolvedP);
}

let resolvedP;

try {
Expand Down Expand Up @@ -716,7 +728,7 @@ export class ZipFS extends BasePortableFakeFS {

const fileIndex = this.entries.get(resolvedP);
if (resolveLastComponent && fileIndex !== undefined) {
if (this.isSymbolicLink(fileIndex)) {
if (this.symlinkCount !== 0 && this.isSymbolicLink(fileIndex)) {
const target = this.getFileSource(fileIndex).toString() as PortablePath;
return this.resolveFilename(reason, ppath.resolve(ppath.dirname(resolvedP), target), true);
} else {
Expand All @@ -736,7 +748,7 @@ export class ZipFS extends BasePortableFakeFS {
throw errors.ENOTDIR(reason);

resolvedP = ppath.resolve(parentP, ppath.basename(resolvedP));
if (!resolveLastComponent)
if (!resolveLastComponent || this.symlinkCount === 0)
break;

const index = this.libzip.name.locate(this.zip, resolvedP.slice(1));
Expand Down Expand Up @@ -823,6 +835,9 @@ export class ZipFS extends BasePortableFakeFS {
}

private isSymbolicLink(index: number) {
if (this.symlinkCount === 0)
return false;

const attrs = this.libzip.file.getExternalAttributes(this.zip, index, 0, 0, this.libzip.uint08S, this.libzip.uint32S);
if (attrs === -1)
throw new Error(this.libzip.error.strerror(this.libzip.getError(this.zip)));
Expand Down Expand Up @@ -1099,9 +1114,10 @@ export class ZipFS extends BasePortableFakeFS {
this.registerEntry(resolvedP, index);

const rc = this.libzip.file.setExternalAttributes(this.zip, index, 0, 0, this.libzip.ZIP_OPSYS_UNIX, (0o120000 | 0o777) << 16);
if (rc === -1) {
if (rc === -1)
throw new Error(this.libzip.error.strerror(this.libzip.getError(this.zip)));
}

this.symlinkCount += 1;
}

readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>;
Expand Down
4 changes: 3 additions & 1 deletion packages/yarnpkg-libzip/artifacts/exported.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
"_zipstruct_stat_size",
"_zipstruct_stat_mtime",
"_zipstruct_error",
"_zipstruct_errorS"
"_zipstruct_errorS",

"_zip_ext_count_symlinks"
]
26 changes: 15 additions & 11 deletions packages/yarnpkg-libzip/sources/libzipAsync.js

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions packages/yarnpkg-libzip/sources/libzipSync.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/yarnpkg-libzip/sources/makeInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const makeInterface = (libzip: EmscriptenModule) => ({
setCompression: libzip.cwrap(`zip_set_file_compression`, `number`, [`number`, ...number64, `number`, `number`]),
},

ext: {
countSymlinks: libzip.cwrap(`zip_ext_count_symlinks`, `number`, [`number`]),
},

error: {
initWithCode: libzip.cwrap(`zip_error_init_with_code`, null, [`number`, `number`]),
strerror: libzip.cwrap(`zip_error_strerror`, `string`, [`number`]),
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

0 comments on commit f6f7788

Please sign in to comment.