Skip to content

Commit

Permalink
chore: added symbolic link information to the file stats
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 20, 2024
1 parent d1b05b9 commit 846a762
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/client/handlers/VaultsSecretsGetFileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/vaults/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type INode = number;

type StatEncoded = {
isSymbolicLink: boolean;
symbolicLinkTarget?: string,
dev: number;
ino: number;
mode: number;
Expand Down

0 comments on commit 846a762

Please sign in to comment.