@vltpkg/tar 1.3.8 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -13
- package/dist/clonefile.d.ts +14 -0
- package/dist/clonefile.js +92 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/link-tree.d.ts +27 -14
- package/dist/link-tree.js +97 -21
- package/dist/store-entry.d.ts +12 -4
- package/dist/store-entry.js +23 -7
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -76,14 +76,16 @@ See [Global store](#global-store).
|
|
|
76
76
|
|
|
77
77
|
A global store entry is a tarball exploded once into a directory, with
|
|
78
78
|
a sidecar index at `<entry>.json` (`StoreIndex`). Packages are then
|
|
79
|
-
materialized by hardlinking files
|
|
80
|
-
again. Publishing entries atomically
|
|
81
|
-
into place) is up to the caller.
|
|
79
|
+
materialized by hardlinking files, or cloning the directory, instead
|
|
80
|
+
of unpacking the tarball again. Publishing entries atomically
|
|
81
|
+
(sidecar, then rename the dir into place) is up to the caller.
|
|
82
82
|
|
|
83
83
|
The vlt CLI keeps its global store under `<cache>/store/v1`, filled by
|
|
84
84
|
a background process, and installs from it with the `store-linker`
|
|
85
|
-
config (`auto` by default, `hardlink`, `copy`; `unpack` skips
|
|
86
|
-
`auto`
|
|
85
|
+
config (`auto` by default, `hardlink`, `clone`, `copy`; `unpack` skips
|
|
86
|
+
it). `auto` links on Linux, clones on macOS where
|
|
87
|
+
[`cloneAvailable()`](#cloneavailable) is true, and means `unpack`
|
|
88
|
+
everywhere else.
|
|
87
89
|
|
|
88
90
|
### unpackToStoreSync(tarData, dir)
|
|
89
91
|
|
|
@@ -98,15 +100,16 @@ The index has files (`[path, size, exec]`, sorted), every directory
|
|
|
98
100
|
normalized `bins`, `name`, `version` and `manifest` (package.json as
|
|
99
101
|
compact JSON text, if valid; lets reify skip reading it back).
|
|
100
102
|
|
|
101
|
-
### linkFromStore(storeEntry, target, { copy })
|
|
103
|
+
### linkFromStore(storeEntry, target, { copy, clone })
|
|
102
104
|
|
|
103
105
|
Hardlink every file of a store entry into a sibling temp dir
|
|
104
106
|
(package.json last), then rename it to `target`. Returns
|
|
105
|
-
`{ how, index }`: `how` is `'link'`,
|
|
106
|
-
copied instead (see below).
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
`{ how, index }`: `how` is `'link'`, `'clone'` when the directory was
|
|
108
|
+
cloned, or `'copy'` when files were copied instead (see below).
|
|
109
|
+
Returns `false`, creating nothing, if the sidecar is missing or
|
|
110
|
+
invalid, the entry is not a directory, the target's parent is a
|
|
111
|
+
symlink, or a clone fails (see below). An entry with a missing file is
|
|
112
|
+
removed and `false` returned. Two index paths that collide on a
|
|
110
113
|
case-insensitive target (`EEXIST`) also return `false`.
|
|
111
114
|
|
|
112
115
|
`EXDEV`, `EPERM`, `EACCES` and `ENOTSUP` switch the process to copying
|
|
@@ -115,11 +118,38 @@ the target's parent exist (overlayfs cross-layer links) does the same.
|
|
|
115
118
|
`EMLINK` copies that file only. Other link errors throw. Every file is
|
|
116
119
|
copied with `copy: true`, or when package.json is copied after another
|
|
117
120
|
file was linked: a private package.json means nothing is shared. A
|
|
118
|
-
copy
|
|
121
|
+
copy, or a link of a package with install scripts (reify copies it
|
|
122
|
+
before they run), touches the entry's copied marker
|
|
123
|
+
(`<entry>.copied`): its mtime is the last time one did.
|
|
124
|
+
|
|
125
|
+
With `clone: true` the whole entry directory is cloned copy-on-write
|
|
126
|
+
into the temp dir in one `clonefile(2)` call instead (see
|
|
127
|
+
[`cloneDir`](#clonefile)). A clone is checked against the index (the
|
|
128
|
+
names in every directory, since a clone holds whatever the entry
|
|
129
|
+
holds), and, sharing no inode with the store, marks the entry copied.
|
|
130
|
+
Nothing written into a clone reaches the store, so `copy` changes
|
|
131
|
+
nothing about it, and install scripts need no copy before they run. A
|
|
132
|
+
failed clone is a store miss, so the caller unpacks: on APFS,
|
|
133
|
+
hardlinking file by file is slower than that. Whatever it left in the
|
|
134
|
+
temp dir is removed. After `ENOTSUP`, `EXDEV`, `EPERM` or `EACCES`,
|
|
135
|
+
every later clone is a miss without trying, for the rest of the
|
|
136
|
+
process.
|
|
119
137
|
|
|
120
138
|
`VLT_STORE_VERIFY=1` checks the linked package.json size against the
|
|
121
139
|
index and removes the entry on a mismatch (debugging aid).
|
|
122
140
|
|
|
141
|
+
### clonefile
|
|
142
|
+
|
|
143
|
+
`cloneAvailable()` is true on macOS with a Node whose `node:ffi` (26.1
|
|
144
|
+
and later) loads: the permission model denies it without
|
|
145
|
+
`--allow-ffi`. That is what `cloneDir(src, dst)` calls `clonefile(2)`
|
|
146
|
+
through: it clones the directory `src` to `dst`, which must not exist,
|
|
147
|
+
and returns `true` or the errno code of the failure (`ENOTSUP`
|
|
148
|
+
wherever it is unavailable: another platform, no usable `node:ffi`, a
|
|
149
|
+
filesystem without clones, or an ffi call that throws, after which it
|
|
150
|
+
stays unavailable). `node:ffi` is loaded on the first call of either,
|
|
151
|
+
once, and its experimental warning is swallowed.
|
|
152
|
+
|
|
123
153
|
### readStoreIndex(storeEntry)
|
|
124
154
|
|
|
125
155
|
The sidecar index, or `undefined` if missing or invalid.
|
|
@@ -141,7 +171,9 @@ Sidecar path: `<storeEntry>.json`.
|
|
|
141
171
|
copied marker or install scripts (copied before they run), i.e.
|
|
142
172
|
nlink cannot show use.
|
|
143
173
|
- `storeCopiedPath(storeEntry)`, `markStoreEntryCopied(storeEntry)`:
|
|
144
|
-
the copied marker, and its
|
|
174
|
+
the copied marker, and its touch (created the first time).
|
|
175
|
+
- `storeEntryLastCopied(storeEntry)`: the copied marker's mtime in ms,
|
|
176
|
+
else `storeEntryTime(storeEntry)`.
|
|
145
177
|
- `storeEntryTime(storeEntry)`: sidecar mtime in ms (dir mtime without
|
|
146
178
|
one, else 0).
|
|
147
179
|
- `removeStoreEntry(storeEntry)`: remove the dir, then the sidecar and
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True where {@link cloneDir} can work: macOS, on a Node whose
|
|
3
|
+
* `node:ffi` loads. Being built in is not enough: the permission model
|
|
4
|
+
* without `--allow-ffi` denies it. Loads it, once.
|
|
5
|
+
*/
|
|
6
|
+
export declare const cloneAvailable: () => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Clone the directory `src` to `dst`, which must not exist, with
|
|
9
|
+
* `clonefile(2)`. Returns true, or the errno code of the failure:
|
|
10
|
+
* `ENOTSUP` where cloning is unavailable (not macOS, no `node:ffi`,
|
|
11
|
+
* a filesystem without clones), `EXDEV` across volumes, `ENOENT` for a
|
|
12
|
+
* missing source, and so on.
|
|
13
|
+
*/
|
|
14
|
+
export declare const cloneDir: (src: string, dst: string) => true | string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isBuiltin } from 'node:module';
|
|
2
|
+
// darwin errno values clonefile(2) can set
|
|
3
|
+
const codes = {
|
|
4
|
+
1: 'EPERM',
|
|
5
|
+
2: 'ENOENT',
|
|
6
|
+
5: 'EIO',
|
|
7
|
+
13: 'EACCES',
|
|
8
|
+
17: 'EEXIST',
|
|
9
|
+
18: 'EXDEV',
|
|
10
|
+
20: 'ENOTDIR',
|
|
11
|
+
22: 'EINVAL',
|
|
12
|
+
28: 'ENOSPC',
|
|
13
|
+
45: 'ENOTSUP',
|
|
14
|
+
62: 'ELOOP',
|
|
15
|
+
63: 'ENAMETOOLONG',
|
|
16
|
+
};
|
|
17
|
+
// null: tried and unavailable
|
|
18
|
+
let lib;
|
|
19
|
+
const load = () => {
|
|
20
|
+
if (lib !== undefined)
|
|
21
|
+
return lib;
|
|
22
|
+
lib = null;
|
|
23
|
+
if (process.platform !== 'darwin' || !isBuiltin('node:ffi')) {
|
|
24
|
+
return lib;
|
|
25
|
+
}
|
|
26
|
+
// `node:ffi` warns once when loaded, being experimental. The CLI runs
|
|
27
|
+
// with --no-warnings; anyone else would see it on their first
|
|
28
|
+
// install, so that one warning is swallowed here and nothing else.
|
|
29
|
+
const emitWarning = process.emitWarning;
|
|
30
|
+
process.emitWarning = (warning, ...rest) => {
|
|
31
|
+
const [type] = rest;
|
|
32
|
+
const name = typeof type === 'string' ? type : (type?.type);
|
|
33
|
+
if (name !== 'ExperimentalWarning' ||
|
|
34
|
+
!/\bFFI\b/.test(String(warning))) {
|
|
35
|
+
emitWarning.call(process, warning, ...rest);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
const ffi = process.getBuiltinModule('node:ffi');
|
|
40
|
+
const system = new ffi.DynamicLibrary('libSystem.B.dylib');
|
|
41
|
+
lib = {
|
|
42
|
+
clonefile: system.getFunction('clonefile', {
|
|
43
|
+
return: 'int32',
|
|
44
|
+
arguments: ['string', 'string', 'uint32'],
|
|
45
|
+
}),
|
|
46
|
+
error: system.getFunction('__error', {
|
|
47
|
+
return: 'pointer',
|
|
48
|
+
arguments: [],
|
|
49
|
+
}),
|
|
50
|
+
getInt32: ffi.getInt32,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// the permission model without --allow-ffi, or a libSystem
|
|
55
|
+
// without clonefile: as good as no ffi at all
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
process.emitWarning = emitWarning;
|
|
59
|
+
}
|
|
60
|
+
return lib;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* True where {@link cloneDir} can work: macOS, on a Node whose
|
|
64
|
+
* `node:ffi` loads. Being built in is not enough: the permission model
|
|
65
|
+
* without `--allow-ffi` denies it. Loads it, once.
|
|
66
|
+
*/
|
|
67
|
+
export const cloneAvailable = () => !!load();
|
|
68
|
+
/**
|
|
69
|
+
* Clone the directory `src` to `dst`, which must not exist, with
|
|
70
|
+
* `clonefile(2)`. Returns true, or the errno code of the failure:
|
|
71
|
+
* `ENOTSUP` where cloning is unavailable (not macOS, no `node:ffi`,
|
|
72
|
+
* a filesystem without clones), `EXDEV` across volumes, `ENOENT` for a
|
|
73
|
+
* missing source, and so on.
|
|
74
|
+
*/
|
|
75
|
+
export const cloneDir = (src, dst) => {
|
|
76
|
+
const l = load();
|
|
77
|
+
if (!l)
|
|
78
|
+
return 'ENOTSUP';
|
|
79
|
+
try {
|
|
80
|
+
if (l.clonefile(src, dst, 0) === 0)
|
|
81
|
+
return true;
|
|
82
|
+
// read errno right away, before anything else can set it
|
|
83
|
+
const errno = l.getInt32(l.error(), 0);
|
|
84
|
+
return codes[errno] ?? `E${errno}`;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// `node:ffi` is experimental: a call that throws (a changed
|
|
88
|
+
// signature or type) degrades to no clones, never fails an install
|
|
89
|
+
lib = null;
|
|
90
|
+
return 'ENOTSUP';
|
|
91
|
+
}
|
|
92
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/link-tree.d.ts
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
import type { StoreIndex } from './store-index.ts';
|
|
2
2
|
/**
|
|
3
3
|
* How reify places packages: `auto` and `hardlink` link from the global
|
|
4
|
-
* store, `copy` copies from it, `unpack`
|
|
4
|
+
* store, `clone` clones from it (macOS), `copy` copies from it, `unpack`
|
|
5
|
+
* skips it.
|
|
5
6
|
*/
|
|
6
|
-
export type StoreLinker = 'auto' | 'hardlink' | 'copy' | 'unpack';
|
|
7
|
+
export type StoreLinker = 'auto' | 'hardlink' | 'clone' | 'copy' | 'unpack';
|
|
7
8
|
/**
|
|
8
|
-
* How a store entry was placed (`
|
|
9
|
-
*
|
|
9
|
+
* How a store entry was placed (`clone`: the whole directory cloned
|
|
10
|
+
* copy-on-write; `copy`: every file copied, for `copy` or a downgrade)
|
|
11
|
+
* and its index, or false on a miss.
|
|
10
12
|
*/
|
|
11
13
|
export type StoreLinkResult = {
|
|
12
|
-
how: 'link' | 'copy';
|
|
14
|
+
how: 'link' | 'clone' | 'copy';
|
|
13
15
|
index: StoreIndex;
|
|
14
16
|
} | false;
|
|
15
17
|
export type LinkFromStoreOptions = {
|
|
16
18
|
/** copy every file instead of hardlinking */
|
|
17
19
|
copy?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* clone the entry directory copy-on-write (`clonefile(2)`: macOS on
|
|
22
|
+
* APFS) instead of placing files one by one. A failed clone is a
|
|
23
|
+
* store miss, so the caller unpacks: on APFS, hardlinking file by
|
|
24
|
+
* file is slower than that. Where a clone cannot work at all (no
|
|
25
|
+
* clones on this filesystem, another volume), every later call is a
|
|
26
|
+
* miss without trying. A clone shares no file with the store, so it
|
|
27
|
+
* needs no copy on top, for `copy` or for install scripts.
|
|
28
|
+
*/
|
|
29
|
+
clone?: boolean;
|
|
18
30
|
};
|
|
19
31
|
/**
|
|
20
32
|
* Materialize a global store entry at `target` from its sidecar index:
|
|
21
|
-
* hardlink each file into a sibling temp dir (package.json last),
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
33
|
+
* hardlink each file into a sibling temp dir (package.json last), or
|
|
34
|
+
* with `clone` clone the whole entry there, then rename it into place.
|
|
35
|
+
* Files that cannot be linked are copied; if package.json is copied
|
|
36
|
+
* after another file was linked, the whole package is copied, so a
|
|
37
|
+
* private package.json means nothing is shared. Returns how, with the
|
|
38
|
+
* index, or false, leaving `target` untouched, on a store miss (no
|
|
39
|
+
* valid index, entry not a directory, symlinked target parent, a
|
|
40
|
+
* failed clone), a name clash on a case-insensitive target, or a
|
|
41
|
+
* damaged entry, which is removed.
|
|
29
42
|
*/
|
|
30
|
-
export declare const linkFromStore: (storeEntry: string, target: string, { copy }?: LinkFromStoreOptions) => StoreLinkResult;
|
|
43
|
+
export declare const linkFromStore: (storeEntry: string, target: string, { copy, clone }?: LinkFromStoreOptions) => StoreLinkResult;
|
package/dist/link-tree.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { chmodSync, linkSync, lstatSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync, } from 'node:fs';
|
|
1
|
+
import { chmodSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
2
|
import { dirname, sep } from 'node:path';
|
|
3
3
|
import { debuglog } from 'node:util';
|
|
4
4
|
import { rimrafSync } from 'rimraf';
|
|
5
|
+
import { cloneDir } from "./clonefile.js";
|
|
5
6
|
import { markStoreEntryCopied, removeStoreEntry, } from "./store-entry.js";
|
|
6
7
|
import { readStoreIndex } from "./store-index.js";
|
|
7
8
|
import { tmpName } from "./unpack.js";
|
|
@@ -16,6 +17,66 @@ const downgrade = (code) => {
|
|
|
16
17
|
copyAll = true;
|
|
17
18
|
debug('global store: linking failed, copying from now on', code);
|
|
18
19
|
};
|
|
20
|
+
// Same for clones: no clonefile, no clones on this filesystem, another
|
|
21
|
+
// volume, or permissions.
|
|
22
|
+
let cloneNone = false;
|
|
23
|
+
// Index paths are validated relative '/'-paths: concatenation is safe
|
|
24
|
+
// and much cheaper than join() on the per-file hot path.
|
|
25
|
+
const native = (p) => sep === '/' ? p : p.replaceAll('/', sep);
|
|
26
|
+
// false: not cloned
|
|
27
|
+
const cloneEntry = (storeEntry, tmp) => {
|
|
28
|
+
const res = cloneDir(storeEntry, tmp);
|
|
29
|
+
if (res === true)
|
|
30
|
+
return true;
|
|
31
|
+
if (res === 'ENOTSUP' ||
|
|
32
|
+
res === 'EXDEV' ||
|
|
33
|
+
res === 'EPERM' ||
|
|
34
|
+
res === 'EACCES') {
|
|
35
|
+
cloneNone = true;
|
|
36
|
+
debug('global store: cloning failed, unpacking from now on', res);
|
|
37
|
+
}
|
|
38
|
+
// ENOENT (entry gone) and the rest: a miss for this entry only
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A clone holds whatever the entry holds, so a file missing from the
|
|
43
|
+
* entry is silently missing from the clone: count the names in every
|
|
44
|
+
* directory against the index (one readdir per directory, far cheaper
|
|
45
|
+
* than a stat per file). 'damaged' on any difference, or, with
|
|
46
|
+
* VLT_STORE_VERIFY=1, when package.json changed size.
|
|
47
|
+
*/
|
|
48
|
+
const checkClone = (tmp, index) => {
|
|
49
|
+
const counts = new Map([['', 0]]);
|
|
50
|
+
for (const d of index.dirs)
|
|
51
|
+
counts.set(d, 0);
|
|
52
|
+
for (const p of [...index.dirs, ...index.files.map(f => f[0])]) {
|
|
53
|
+
const i = p.lastIndexOf('/');
|
|
54
|
+
const d = i === -1 ? '' : p.slice(0, i);
|
|
55
|
+
const n = counts.get(d);
|
|
56
|
+
// a directory the index does not list: not a valid entry
|
|
57
|
+
if (n === undefined)
|
|
58
|
+
return 'damaged';
|
|
59
|
+
counts.set(d, n + 1);
|
|
60
|
+
}
|
|
61
|
+
for (const [d, n] of counts) {
|
|
62
|
+
let names;
|
|
63
|
+
try {
|
|
64
|
+
names = readdirSync(d ? tmp + sep + native(d) : tmp);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// a directory the entry does not have
|
|
68
|
+
return 'damaged';
|
|
69
|
+
}
|
|
70
|
+
if (names.length !== n)
|
|
71
|
+
return 'damaged';
|
|
72
|
+
}
|
|
73
|
+
const pj = index.files.find(f => f[0] === 'package.json');
|
|
74
|
+
if (verify &&
|
|
75
|
+
pj &&
|
|
76
|
+
statSync(tmp + sep + 'package.json').size !== pj[1]) {
|
|
77
|
+
return 'damaged';
|
|
78
|
+
}
|
|
79
|
+
};
|
|
19
80
|
// false: the source is gone, i.e. the store entry is damaged
|
|
20
81
|
const place = (src, dst, exec, copy) => {
|
|
21
82
|
if (!copy && !copyAll) {
|
|
@@ -68,11 +129,6 @@ const place = (src, dst, exec, copy) => {
|
|
|
68
129
|
* package.json copied after another file was linked.
|
|
69
130
|
*/
|
|
70
131
|
const fill = (storeEntry, tmp, index, copy) => {
|
|
71
|
-
// Index paths are validated relative '/'-paths: concatenation is
|
|
72
|
-
// safe and much cheaper than join() on this per-file hot path.
|
|
73
|
-
const native = sep === '/' ?
|
|
74
|
-
(p) => p
|
|
75
|
-
: (p) => p.replaceAll('/', sep);
|
|
76
132
|
const put = ([p, , exec]) => place(storeEntry + sep + native(p), tmp + sep + native(p), exec, copy);
|
|
77
133
|
try {
|
|
78
134
|
for (const d of index.dirs)
|
|
@@ -110,16 +166,20 @@ const fill = (storeEntry, tmp, index, copy) => {
|
|
|
110
166
|
};
|
|
111
167
|
/**
|
|
112
168
|
* Materialize a global store entry at `target` from its sidecar index:
|
|
113
|
-
* hardlink each file into a sibling temp dir (package.json last),
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
169
|
+
* hardlink each file into a sibling temp dir (package.json last), or
|
|
170
|
+
* with `clone` clone the whole entry there, then rename it into place.
|
|
171
|
+
* Files that cannot be linked are copied; if package.json is copied
|
|
172
|
+
* after another file was linked, the whole package is copied, so a
|
|
173
|
+
* private package.json means nothing is shared. Returns how, with the
|
|
174
|
+
* index, or false, leaving `target` untouched, on a store miss (no
|
|
175
|
+
* valid index, entry not a directory, symlinked target parent, a
|
|
176
|
+
* failed clone), a name clash on a case-insensitive target, or a
|
|
177
|
+
* damaged entry, which is removed.
|
|
121
178
|
*/
|
|
122
|
-
export const linkFromStore = (storeEntry, target, { copy = false } = {}) => {
|
|
179
|
+
export const linkFromStore = (storeEntry, target, { copy = false, clone = false } = {}) => {
|
|
180
|
+
// no clones here: a miss, without reading anything
|
|
181
|
+
if (clone && cloneNone)
|
|
182
|
+
return false;
|
|
123
183
|
const index = readStoreIndex(storeEntry);
|
|
124
184
|
if (!index || !lstatSync(storeEntry, noThrow)?.isDirectory()) {
|
|
125
185
|
return false;
|
|
@@ -133,9 +193,17 @@ export const linkFromStore = (storeEntry, target, { copy = false } = {}) => {
|
|
|
133
193
|
const og = tmp + '.ORIGINAL';
|
|
134
194
|
let succeeded = false;
|
|
135
195
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
196
|
+
// whatever a failed clone left in tmp goes with it, below
|
|
197
|
+
if (clone && !cloneEntry(storeEntry, tmp))
|
|
198
|
+
return false;
|
|
199
|
+
// a clone is copy-on-write: nothing written into it reaches the
|
|
200
|
+
// store, so it needs no copy on top
|
|
201
|
+
let copied = !clone && copy;
|
|
202
|
+
if (!clone)
|
|
203
|
+
mkdirSync(tmp);
|
|
204
|
+
let miss = clone ?
|
|
205
|
+
checkClone(tmp, index)
|
|
206
|
+
: fill(storeEntry, tmp, index, copied);
|
|
139
207
|
if (miss === 'mixed') {
|
|
140
208
|
rimrafSync(tmp);
|
|
141
209
|
mkdirSync(tmp);
|
|
@@ -160,11 +228,19 @@ export const linkFromStore = (storeEntry, target, { copy = false } = {}) => {
|
|
|
160
228
|
renameSync(tmp, target);
|
|
161
229
|
if (targetExists)
|
|
162
230
|
rimrafSync(og);
|
|
163
|
-
// nlink stays 1
|
|
164
|
-
|
|
231
|
+
// nlink stays 1 (a clone shares blocks, not inodes; reify copies
|
|
232
|
+
// a linked package right before its install scripts run): tell
|
|
233
|
+
// prune-store it was used, and when
|
|
234
|
+
if (clone || copied || copyAll || index.scripts) {
|
|
165
235
|
markStoreEntryCopied(storeEntry);
|
|
236
|
+
}
|
|
166
237
|
succeeded = true;
|
|
167
|
-
return {
|
|
238
|
+
return {
|
|
239
|
+
how: clone ? 'clone'
|
|
240
|
+
: copied || copyAll ? 'copy'
|
|
241
|
+
: 'link',
|
|
242
|
+
index,
|
|
243
|
+
};
|
|
168
244
|
}
|
|
169
245
|
finally {
|
|
170
246
|
if (!succeeded) {
|
package/dist/store-entry.d.ts
CHANGED
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const storeEntryNames: (root: string) => string[];
|
|
6
6
|
/**
|
|
7
|
-
* Marker next to a global store entry: some install copied
|
|
8
|
-
* its files' nlink cannot show use
|
|
7
|
+
* Marker next to a global store entry: some install copied or cloned
|
|
8
|
+
* from it, so its files' nlink cannot show use; its mtime is the last
|
|
9
|
+
* time one did. See {@link markStoreEntryCopied}.
|
|
9
10
|
*/
|
|
10
11
|
export declare const storeCopiedPath: (storeEntry: string) => string;
|
|
11
12
|
/**
|
|
12
|
-
* Mark a global store entry as copied from. Called on
|
|
13
|
-
*
|
|
13
|
+
* Mark a global store entry as copied from, now. Called on uses that
|
|
14
|
+
* nlink cannot show (copies, clones, links copied before install
|
|
15
|
+
* scripts): one create per entry, then a touch per use, so prune-store
|
|
16
|
+
* can tell an entry still in use from one long forgotten.
|
|
14
17
|
*/
|
|
15
18
|
export declare const markStoreEntryCopied: (storeEntry: string) => void;
|
|
16
19
|
/**
|
|
@@ -23,6 +26,11 @@ export declare const removeStoreEntry: (storeEntry: string) => void;
|
|
|
23
26
|
* else its dir's, else 0.
|
|
24
27
|
*/
|
|
25
28
|
export declare const storeEntryTime: (storeEntry: string) => number;
|
|
29
|
+
/**
|
|
30
|
+
* When a global store entry was last copied from, in ms: its marker's
|
|
31
|
+
* mtime, else when it was written ({@link storeEntryTime}).
|
|
32
|
+
*/
|
|
33
|
+
export declare const storeEntryLastCopied: (storeEntry: string) => number;
|
|
26
34
|
/**
|
|
27
35
|
* True if the global store entry has a valid sidecar and dir, and was
|
|
28
36
|
* copied from (marker) or has install scripts (copied before they
|
package/dist/store-entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { closeSync, lstatSync, openSync, readdirSync, readFileSync, statSync, } from 'node:fs';
|
|
1
|
+
import { closeSync, lstatSync, openSync, readdirSync, readFileSync, statSync, utimesSync, } from 'node:fs';
|
|
2
2
|
import { join, relative } from 'node:path';
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
4
4
|
import { rimrafSync } from 'rimraf';
|
|
@@ -28,20 +28,30 @@ export const storeEntryNames = (root) => {
|
|
|
28
28
|
return [...hexes].sort();
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
* Marker next to a global store entry: some install copied
|
|
32
|
-
* its files' nlink cannot show use
|
|
31
|
+
* Marker next to a global store entry: some install copied or cloned
|
|
32
|
+
* from it, so its files' nlink cannot show use; its mtime is the last
|
|
33
|
+
* time one did. See {@link markStoreEntryCopied}.
|
|
33
34
|
*/
|
|
34
35
|
export const storeCopiedPath = (storeEntry) => storeEntry + '.copied';
|
|
35
36
|
/**
|
|
36
|
-
* Mark a global store entry as copied from. Called on
|
|
37
|
-
*
|
|
37
|
+
* Mark a global store entry as copied from, now. Called on uses that
|
|
38
|
+
* nlink cannot show (copies, clones, links copied before install
|
|
39
|
+
* scripts): one create per entry, then a touch per use, so prune-store
|
|
40
|
+
* can tell an entry still in use from one long forgotten.
|
|
38
41
|
*/
|
|
39
42
|
export const markStoreEntryCopied = (storeEntry) => {
|
|
43
|
+
const marker = storeCopiedPath(storeEntry);
|
|
40
44
|
try {
|
|
41
|
-
|
|
45
|
+
const now = new Date();
|
|
46
|
+
utimesSync(marker, now, now);
|
|
42
47
|
}
|
|
43
48
|
catch {
|
|
44
|
-
|
|
49
|
+
try {
|
|
50
|
+
closeSync(openSync(marker, 'a'));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// prune-store may drop it: only a re-explode
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
};
|
|
47
57
|
/**
|
|
@@ -59,6 +69,12 @@ export const removeStoreEntry = (storeEntry) => {
|
|
|
59
69
|
*/
|
|
60
70
|
export const storeEntryTime = (storeEntry) => (statSync(storeIndexPath(storeEntry), noThrow) ??
|
|
61
71
|
statSync(storeEntry, noThrow))?.mtimeMs ?? 0;
|
|
72
|
+
/**
|
|
73
|
+
* When a global store entry was last copied from, in ms: its marker's
|
|
74
|
+
* mtime, else when it was written ({@link storeEntryTime}).
|
|
75
|
+
*/
|
|
76
|
+
export const storeEntryLastCopied = (storeEntry) => statSync(storeCopiedPath(storeEntry), noThrow)?.mtimeMs ??
|
|
77
|
+
storeEntryTime(storeEntry);
|
|
62
78
|
/**
|
|
63
79
|
* True if the global store entry has a valid sidecar and dir, and was
|
|
64
80
|
* copied from (marker) or has install scripts (copied before they
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/tar",
|
|
3
3
|
"description": "An extremely limited and very fast tar extractor",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/error-cause": "1.
|
|
17
|
-
"@vltpkg/types": "1.
|
|
16
|
+
"@vltpkg/error-cause": "1.4.0",
|
|
17
|
+
"@vltpkg/types": "1.4.0",
|
|
18
18
|
"rimraf": "^6.1.2",
|
|
19
19
|
"tar": "^7.5.2"
|
|
20
20
|
},
|
|
@@ -60,6 +60,11 @@
|
|
|
60
60
|
"default": "./dist/index.js"
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
|
+
"./clonefile": {
|
|
64
|
+
"import": {
|
|
65
|
+
"default": "./dist/clonefile.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
63
68
|
"./link-tree": {
|
|
64
69
|
"import": {
|
|
65
70
|
"default": "./dist/link-tree.js"
|