Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
4d437e2ff1
commit
19b92895aa
1 changed files with 12 additions and 6 deletions
|
|
@ -12,15 +12,21 @@ type FileMode = (typeof FILE_MODES)[keyof typeof FILE_MODES];
|
||||||
* correct mode or does not exist.
|
* correct mode or does not exist.
|
||||||
*/
|
*/
|
||||||
export const ensureFileMode = async (filePath: string, mode: FileMode): Promise<boolean> => {
|
export const ensureFileMode = async (filePath: string, mode: FileMode): Promise<boolean> => {
|
||||||
|
let stat;
|
||||||
try {
|
try {
|
||||||
const stat = await fs.stat(filePath);
|
stat = await fs.stat(filePath);
|
||||||
if ((stat.mode & 0o777) !== mode) {
|
} catch (error) {
|
||||||
await fs.chmod(filePath, mode);
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
} catch {
|
throw error;
|
||||||
// File does not exist or cannot be stat'd — nothing to fix.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((stat.mode & 0o777) !== mode) {
|
||||||
|
await fs.chmod(filePath, mode);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue