refactor: use os.userInfo when setting uid/gid in mount commands

This commit is contained in:
Nicolas Meienberger 2025-12-28 13:40:31 +01:00
parent 2bee6c0751
commit 1dd43ad9f1
3 changed files with 10 additions and 7 deletions

View file

@ -51,13 +51,14 @@ const mount = async (config: BackendConfig, mountPath: string) => {
await fs.mkdir(mountPath, { recursive: true });
await fs.mkdir(SSH_KEYS_DIR, { recursive: true });
const { uid, gid } = os.userInfo();
const options = [
"reconnect",
"ServerAliveInterval=15",
"ServerAliveCountMax=3",
"allow_other",
"uid=1000",
"gid=1000",
`uid=${uid}`,
`gid=${gid}`,
];
if (config.skipHostKeyCheck || !config.knownHosts) {
@ -113,7 +114,7 @@ const mount = async (config: BackendConfig, mountPath: string) => {
};
try {
return await withTimeout(run(), OPERATION_TIMEOUT, "SFTP mount");
return await withTimeout(run(), OPERATION_TIMEOUT * 2, "SFTP mount");
} catch (error) {
const errorMsg = toMessage(error);
logger.error("Error mounting SFTP volume", { error: errorMsg });

View file

@ -39,13 +39,14 @@ const mount = async (config: BackendConfig, path: string) => {
const password = await cryptoUtils.resolveSecret(config.password);
const source = `//${config.server}/${config.share}`;
const { uid, gid } = os.userInfo();
const options = [
`user=${config.username}`,
`pass=${password}`,
`vers=${config.vers}`,
`port=${config.port}`,
"uid=1000",
"gid=1000",
`uid=${uid}`,
`gid=${gid}`,
];
if (config.domain) {

View file

@ -43,9 +43,10 @@ const mount = async (config: BackendConfig, path: string) => {
const port = config.port !== defaultPort ? `:${config.port}` : "";
const source = `${protocol}://${config.server}${port}${config.path}`;
const { uid, gid } = os.userInfo();
const options = config.readOnly
? ["uid=1000", "gid=1000", "file_mode=0444", "dir_mode=0555", "ro"]
: ["uid=1000", "gid=1000", "file_mode=0664", "dir_mode=0775"];
? [`uid=${uid}`, `gid=${gid}`, "file_mode=0444", "dir_mode=0555", "ro"]
: [`uid=${uid}`, `gid=${gid}`, "file_mode=0664", "dir_mode=0775"];
if (config.username && config.password) {
const password = await cryptoUtils.resolveSecret(config.password);