From dc7aa9434866dccac025f684afac114e5d2f6512 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 27 Jun 2024 20:27:08 +0300 Subject: [PATCH] Hide dotfiles on Windows (#10376) related #10071 Request from @jdunkerley to hide all dotfiles on Windows. --- .../src/projectManagerShimMiddleware.ts | 26 ++++++++++++++----- .../filesystem/FileSystemListCommand.scala | 13 +++++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts b/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts index ce07aac80dc..db1442efd8a 100644 --- a/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts +++ b/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts @@ -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) + } +} diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/boot/command/filesystem/FileSystemListCommand.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/boot/command/filesystem/FileSystemListCommand.scala index fa93d96eab8..80bfbdc6b5c 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/boot/command/filesystem/FileSystemListCommand.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/boot/command/filesystem/FileSystemListCommand.scala @@ -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(".") + } }