mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 16:25:30 +00:00
fix(session): preserve recording permissions during staging
This commit is contained in:
1 parent
0083c6e8ec
commit
f314b2f2e3
2 files changed
+22
-3
No files matched your search
@@ -74,10 +74,10 @@ function writeFileAtomic(filePath, content, options = {}) {
|
||||
|
||||
let descriptor;
|
||||
try {
|
||||
if (options.validateParent) options.validateParent();
|
||||
descriptor = fs.openSync(tempPath, 'wx', mode);
|
||||
if (options.validateParent) options.validateParent();
|
||||
const existingMode = options.preserveExistingMode ? readExistingFileMode(resolvedPath) : undefined;
|
||||
descriptor = fs.openSync(tempPath, 'wx', existingMode ?? mode);
|
||||
if (options.validateParent) options.validateParent();
|
||||
fs.writeFileSync(descriptor, content, { encoding: options.encoding || 'utf8' });
|
||||
// Restore existing permissions after writing, without applying the process umask a second time.
|
||||
if (existingMode !== undefined) fs.fchmodSync(descriptor, existingMode);
|
||||
|
||||
@@ -125,7 +125,26 @@ if (process.platform !== 'win32') {
|
||||
for (const mode of [0o600, 0o640, 0o660]) {
|
||||
fs.chmodSync(filePath, mode);
|
||||
const next = snapshot(`Permissions ${mode.toString(8)}`);
|
||||
persistCanonicalSnapshot(next, options);
|
||||
const originalWrite = fs.writeFileSync;
|
||||
const observedModes = [];
|
||||
fs.writeFileSync = (destination, contents, writeOptions) => {
|
||||
const readMode = () => (typeof destination === 'number'
|
||||
? fs.fstatSync(destination)
|
||||
: fs.statSync(destination)).mode & 0o777;
|
||||
observedModes.push(readMode());
|
||||
const result = originalWrite(destination, contents, writeOptions);
|
||||
observedModes.push(readMode());
|
||||
return result;
|
||||
};
|
||||
try {
|
||||
persistCanonicalSnapshot(next, options);
|
||||
} finally {
|
||||
fs.writeFileSync = originalWrite;
|
||||
}
|
||||
assert.strictEqual(observedModes.length, 2);
|
||||
for (const observed of observedModes) {
|
||||
assert.strictEqual(observed & ~mode, 0, 'staging must not grant permissions absent from the saved recording');
|
||||
}
|
||||
assert.strictEqual(fs.statSync(filePath).mode & 0o777, mode);
|
||||
assert.deepStrictEqual(JSON.parse(fs.readFileSync(filePath, 'utf8')).latest, next);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user