@jsenv/filesystem
Advanced tools
Comparing version 4.9.2 to 4.9.3
{ | ||
"name": "@jsenv/filesystem", | ||
"version": "4.9.2", | ||
"version": "4.9.3", | ||
"license": "MIT", | ||
@@ -37,4 +37,4 @@ "repository": { | ||
"@jsenv/abort": "4.3.0", | ||
"@jsenv/utils": "2.1.1" | ||
"@jsenv/utils": "2.1.2" | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
import { Abort } from "@jsenv/abort"; | ||
import { | ||
@@ -21,3 +20,2 @@ ensurePathnameTrailingSlash, | ||
{ | ||
signal = new AbortController().signal, | ||
allowUseless = false, | ||
@@ -31,47 +29,37 @@ recursive = false, | ||
const sourceUrl = assertAndNormalizeFileUrl(source); | ||
const removeOperation = Abort.startOperation(); | ||
removeOperation.addAbortSignal(signal); | ||
try { | ||
removeOperation.throwIfAborted(); | ||
const sourceStats = readEntryStatSync(sourceUrl, { | ||
nullIfNotFound: true, | ||
followLink: false, | ||
}); | ||
if (!sourceStats) { | ||
if (allowUseless) { | ||
return; | ||
} | ||
throw new Error(`nothing to remove at ${urlToFileSystemPath(sourceUrl)}`); | ||
const sourceStats = readEntryStatSync(sourceUrl, { | ||
nullIfNotFound: true, | ||
followLink: false, | ||
}); | ||
if (!sourceStats) { | ||
if (allowUseless) { | ||
return; | ||
} | ||
throw new Error(`nothing to remove at ${urlToFileSystemPath(sourceUrl)}`); | ||
} | ||
// https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_class_fs_stats | ||
// FIFO and socket are ignored, not sure what they are exactly and what to do with them | ||
// other libraries ignore them, let's do the same. | ||
if ( | ||
sourceStats.isFile() || | ||
sourceStats.isSymbolicLink() || | ||
sourceStats.isCharacterDevice() || | ||
sourceStats.isBlockDevice() | ||
) { | ||
removeNonDirectory( | ||
sourceUrl.endsWith("/") ? sourceUrl.slice(0, -1) : sourceUrl, | ||
{ | ||
maxRetries, | ||
retryDelay, | ||
}, | ||
); | ||
} else if (sourceStats.isDirectory()) { | ||
const directoryUrl = ensurePathnameTrailingSlash(sourceUrl); | ||
removeDirectorySync(directoryUrl, { | ||
signal: removeOperation.signal, | ||
recursive, | ||
// https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_class_fs_stats | ||
// FIFO and socket are ignored, not sure what they are exactly and what to do with them | ||
// other libraries ignore them, let's do the same. | ||
if ( | ||
sourceStats.isFile() || | ||
sourceStats.isSymbolicLink() || | ||
sourceStats.isCharacterDevice() || | ||
sourceStats.isBlockDevice() | ||
) { | ||
removeNonDirectory( | ||
sourceUrl.endsWith("/") ? sourceUrl.slice(0, -1) : sourceUrl, | ||
{ | ||
maxRetries, | ||
retryDelay, | ||
onlyContent, | ||
}); | ||
} | ||
} finally { | ||
removeOperation.end(); | ||
}, | ||
); | ||
} else if (sourceStats.isDirectory()) { | ||
const directoryUrl = ensurePathnameTrailingSlash(sourceUrl); | ||
removeDirectorySync(directoryUrl, { | ||
recursive, | ||
maxRetries, | ||
retryDelay, | ||
onlyContent, | ||
}); | ||
} | ||
@@ -111,9 +99,5 @@ }; | ||
rootDirectoryUrl, | ||
{ signal, maxRetries, retryDelay, recursive, onlyContent }, | ||
{ maxRetries, retryDelay, recursive, onlyContent }, | ||
) => { | ||
const removeDirectoryOperation = Abort.startOperation(); | ||
removeDirectoryOperation.addAbortSignal(signal); | ||
const visit = (sourceUrl) => { | ||
removeDirectoryOperation.throwIfAborted(); | ||
const sourceStats = readEntryStatSync(sourceUrl, { | ||
@@ -152,3 +136,2 @@ nullIfNotFound: true, | ||
: {}; | ||
removeDirectoryOperation.throwIfAborted(); | ||
removeDirectorySyncNaive(directoryPath, { | ||
@@ -191,3 +174,2 @@ ...optionsFromRecursive, | ||
const removeDirectoryContent = (directoryUrl) => { | ||
removeDirectoryOperation.throwIfAborted(); | ||
const entryNames = readdirSync(new URL(directoryUrl)); | ||
@@ -208,10 +190,6 @@ for (const entryName of entryNames) { | ||
try { | ||
if (onlyContent) { | ||
removeDirectoryContent(rootDirectoryUrl); | ||
} else { | ||
visitDirectory(rootDirectoryUrl); | ||
} | ||
} finally { | ||
removeDirectoryOperation.end(); | ||
if (onlyContent) { | ||
removeDirectoryContent(rootDirectoryUrl); | ||
} else { | ||
visitDirectory(rootDirectoryUrl); | ||
} | ||
@@ -218,0 +196,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136171
3968
+ Added@jsenv/utils@2.1.2(transitive)
- Removed@jsenv/utils@2.1.1(transitive)
Updated@jsenv/utils@2.1.2