diff --git a/src/client/handlers/VaultsSecretsGetFileTree.ts b/src/client/handlers/VaultsSecretsGetFileTree.ts index ddbc8918d..d39bf89b4 100644 --- a/src/client/handlers/VaultsSecretsGetFileTree.ts +++ b/src/client/handlers/VaultsSecretsGetFileTree.ts @@ -5,6 +5,7 @@ import type { SecretFilesMessage, VaultFileNode } from '../types'; import path from 'path'; import { ServerHandler } from '@matrixai/rpc'; import { generateStats } from '../../vaults/fileTree'; +import { StatEncoded } from '../../vaults/types'; import * as vaultsUtils from '../../vaults/utils'; import * as vaultsErrors from '../../vaults/errors'; import * as clientErrors from '../errors'; @@ -46,12 +47,23 @@ class VaultsSecretsGetFileTree extends ServerHandler< for await (const file of files) { try { - const stat = await fs.promises.stat(file); + const stat = await fs.promises.lstat(file); const type = stat.isFile() ? 'FILE' : 'DIRECTORY'; + let stats: StatEncoded | undefined; + + if (input.yieldStats) { + stats = generateStats(stat); + if (stats.isSymbolicLink) { + // @ts-ignore: Again, the types don't fully match, but it works. + stats.symbolicLinkTarget = await fs.promises.readlink(file); + } + } else { + stats = undefined; + } yield { path: file, type: type, - stat: input.yieldStats ? generateStats(stat) : undefined, + stat: stats, }; } catch (e) { throw new clientErrors.ErrorClientFSReadFailed( diff --git a/src/vaults/types.ts b/src/vaults/types.ts index a4609718c..d768ac3b8 100644 --- a/src/vaults/types.ts +++ b/src/vaults/types.ts @@ -155,6 +155,7 @@ type INode = number; type StatEncoded = { isSymbolicLink: boolean; + symbolicLinkTarget?: string, dev: number; ino: number; mode: number;