gestalt-mobile 0.68.1 → 0.68.2
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.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
|
-
import { lstat, mkdir,
|
|
7
|
+
import { lstat, mkdir, readdir, realpath, rename, rm, rmdir } from 'node:fs/promises';
|
|
8
8
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
9
|
import { emptyScratchCounts, } from '../../features/sessions/clean-tmp/use-case.js';
|
|
10
10
|
import { mobileScratchOwnerId, privateDirectory, scratchMarkerName } from './scratch-filesystem.js';
|
|
@@ -15,6 +15,10 @@ import { claimScratchContainment, containmentFenceName } from './containment-fen
|
|
|
15
15
|
function reject(reason) {
|
|
16
16
|
throw new Error(`SCRATCH_CLEANUP_${reason}`);
|
|
17
17
|
}
|
|
18
|
+
/** POSIX payload names need not be UTF-8. Keep their bytes for filesystem calls. */
|
|
19
|
+
function payloadPath(directory, name) {
|
|
20
|
+
return Buffer.concat([Buffer.from(directory), Buffer.from(sep), name]);
|
|
21
|
+
}
|
|
18
22
|
/** Only the managed namespace is traversed. There are no prefix/age/PID legacy recognizers. */
|
|
19
23
|
export class FilesystemScratchCleanup {
|
|
20
24
|
async cleanSession(session, authorized, protectedSessions) {
|
|
@@ -121,10 +125,10 @@ export class FilesystemScratchCleanup {
|
|
|
121
125
|
await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized);
|
|
122
126
|
// Keep authority metadata until disposable payload has been removed. A failed
|
|
123
127
|
// payload deletion is retryable; an interrupted metadata retirement is unknown.
|
|
124
|
-
for (const child of await readdir(directory)) {
|
|
125
|
-
if ([scratchMarkerName, 'leases', '.controller-lock', containmentFenceName].includes(child))
|
|
128
|
+
for (const child of await readdir(directory, { encoding: 'buffer' })) {
|
|
129
|
+
if ([scratchMarkerName, 'leases', '.controller-lock', containmentFenceName].includes(child.toString()))
|
|
126
130
|
continue;
|
|
127
|
-
await rm(
|
|
131
|
+
await rm(payloadPath(directory, child), { recursive: true });
|
|
128
132
|
}
|
|
129
133
|
if ((await readdir(directory)).includes('leases'))
|
|
130
134
|
await rm(join(directory, 'leases'), { recursive: true });
|
|
@@ -234,17 +238,17 @@ export class FilesystemScratchCleanup {
|
|
|
234
238
|
// Even an empty nested namespace is not authority to retire a workspace's
|
|
235
239
|
// contents recursively as another owner's payload.
|
|
236
240
|
if (directory !== root &&
|
|
237
|
-
basename(directory) === 'sessions' &&
|
|
238
|
-
basename(dirname(directory)) === 'tmp')
|
|
241
|
+
basename(directory.toString()) === 'sessions' &&
|
|
242
|
+
basename(dirname(directory.toString())) === 'tmp')
|
|
239
243
|
reject('unrecognized');
|
|
240
|
-
for
|
|
244
|
+
for (const entry of await readdir(directory, { encoding: 'buffer', withFileTypes: true })) {
|
|
241
245
|
const child = entry.name;
|
|
242
246
|
if (++budget.entries > 100_000)
|
|
243
247
|
reject('unrecognized');
|
|
244
248
|
if (directory !== root &&
|
|
245
|
-
[scratchMarkerName, '.controller-lock', '.association-lock', containmentFenceName].includes(child))
|
|
249
|
+
[scratchMarkerName, '.controller-lock', '.association-lock', containmentFenceName].includes(child.toString()))
|
|
246
250
|
reject('unrecognized');
|
|
247
|
-
const path =
|
|
251
|
+
const path = payloadPath(directory, child);
|
|
248
252
|
const info = await lstat(path);
|
|
249
253
|
if ((process.getuid && info.uid !== process.getuid()) ||
|
|
250
254
|
(!info.isDirectory() && !info.isFile() && !info.isSymbolicLink()) ||
|