Hide dotfiles on Windows (#10376)

related #10071

Request from @jdunkerley to hide all dotfiles on Windows.
This commit is contained in:
Dmitry Bushev 2024-06-27 20:27:08 +03:00 committed by GitHub
parent 2f7adb9deb
commit dc7aa94348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 8 deletions

View File

@ -221,13 +221,7 @@ export default function projectManagerShimMiddleware(
const entries: FileSystemEntry[] = []
for (const entryName of entryNames) {
const entryPath = path.join(directoryPath, entryName)
try {
if (isHiddenFile.isHiddenFile(entryPath)) continue
} catch {
// Ignore errors from this library, it occasionally
// fails on windows due to native library loading
// issues.
}
if (isHidden(entryPath)) continue
const stat = await fs.stat(entryPath)
const attributes: Attributes = {
byteSize: stat.size,
@ -470,3 +464,21 @@ function extractProjectMetadata(yamlObj: unknown, jsonObj: unknown): ProjectMeta
}
}
}
/**
* Checks if the provided path should be hidden.
*
* On Windows, files that start with the dot but don't have the hidden property
* should also be hidden.
*/
function isHidden(filePath: string): boolean {
const dotfile = /(^|\/)\.[^/.]/g
try {
return isHiddenFile.isHiddenFile(filePath) || dotfile.test(filePath)
} catch {
// is-hidden-file library occasionally
// fails on Windows due to native library loading
// issues. Fallback to the filename check.
return dotfile.test(filePath)
}
}

View File

@ -58,6 +58,17 @@ object FileSystemListCommand {
private def filterNotHidden(
entries: Seq[FileSystemEntry]
): Seq[FileSystemEntry] =
entries.filterNot(_.path.isHidden)
entries.filterNot(isHidden)
/** Checks whether the provided entry is hidden.
*
* On Windows, files that start with the dot but don't have the hidden
* property should also be hidden.
*
* @param entry the file system entry
* @return `true` if the entry is hidden
*/
private def isHidden(entry: FileSystemEntry): Boolean = {
entry.path.isHidden || entry.path.getName.startsWith(".")
}
}