function trySetSecureMode(pathname: string) { try {
fs.chmodSync(pathname, JSON_FILE_MODE);
} catch { // best-effort on platforms without chmod support
}
}
function trySyncDirectory(pathname: string) {
let fd: number | undefined; try {
fd = fs.openSync(path.dirname(pathname), "r");
fs.fsyncSync(fd);
} catch { // best-effort; some platforms/filesystems do not support syncing directories.
} finally { if (fd !== undefined) { try {
fs.closeSync(fd);
} catch { // best-effort cleanup
}
}
}
}
function resolveJsonWriteTarget(pathname: string): { targetPath: string; followsSymlink: boolean } {
let currentPath = pathname; const visited = new Set<string>();
let followsSymlink = false;
for (;;) {
let stat: fs.Stats; try {
stat = fs.lstatSync(currentPath);
} catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") { throw error;
} return { targetPath: currentPath, followsSymlink };
}
if (!stat.isSymbolicLink()) { return { targetPath: currentPath, followsSymlink };
}
if (visited.has(currentPath)) { const err = new Error(
`Too many symlink levels while resolving ${pathname}`,
) as NodeJS.ErrnoException;
err.code = "ELOOP"; throw err;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.