chore: pr feedbacks
This commit is contained in:
parent
3937c9d4f6
commit
3e805d1223
1 changed files with 30 additions and 29 deletions
|
|
@ -43,36 +43,37 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
|
|
||||||
const credentialsDir = await fs.mkdtemp(`${os.tmpdir()}/zerobyte-smb-`);
|
const credentialsDir = await fs.mkdtemp(`${os.tmpdir()}/zerobyte-smb-`);
|
||||||
const credentialsPath = `${credentialsDir}/credentials`;
|
const credentialsPath = `${credentialsDir}/credentials`;
|
||||||
const credentialsLines: string[] = [];
|
|
||||||
|
|
||||||
if (config.guest) {
|
|
||||||
credentialsLines.push("username=guest", "password=");
|
|
||||||
} else {
|
|
||||||
const password = await cryptoUtils.resolveSecret(config.password ?? "");
|
|
||||||
credentialsLines.push(`username=${config.username ?? ""}`, `password=${password}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.domain) {
|
|
||||||
credentialsLines.push(`domain=${config.domain}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.writeFile(credentialsPath, credentialsLines.join("\n"), { mode: 0o600 });
|
|
||||||
options.push(`credentials=${credentialsPath}`);
|
|
||||||
|
|
||||||
if (config.vers && config.vers !== "auto") {
|
|
||||||
options.push(`vers=${config.vers}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.readOnly) {
|
|
||||||
options.push("ro");
|
|
||||||
}
|
|
||||||
|
|
||||||
const args = ["-t", "cifs", "-o", options.join(","), source, path];
|
|
||||||
|
|
||||||
logger.debug(`Mounting SMB volume ${path}...`);
|
|
||||||
logger.info(`Executing mount: mount ${args.join(" ")}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const credentialsLines: string[] = [];
|
||||||
|
|
||||||
|
if (config.guest) {
|
||||||
|
credentialsLines.push("username=guest", "password=");
|
||||||
|
} else {
|
||||||
|
const password = await cryptoUtils.resolveSecret(config.password ?? "");
|
||||||
|
credentialsLines.push(`username=${config.username ?? ""}`, `password=${password}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.domain) {
|
||||||
|
credentialsLines.push(`domain=${config.domain}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(credentialsPath, credentialsLines.join("\n"), { mode: 0o600 });
|
||||||
|
options.push(`credentials=${credentialsPath}`);
|
||||||
|
|
||||||
|
if (config.vers && config.vers !== "auto") {
|
||||||
|
options.push(`vers=${config.vers}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.readOnly) {
|
||||||
|
options.push("ro");
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = ["-t", "cifs", "-o", options.join(","), source, path];
|
||||||
|
|
||||||
|
logger.debug(`Mounting SMB volume ${path}...`);
|
||||||
|
logger.info(`Executing mount: mount ${args.join(" ")}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await executeMount(args);
|
await executeMount(args);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -81,7 +82,7 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
await fs.rm(credentialsPath, { force: true });
|
await fs.rm(credentialsPath, { force: true });
|
||||||
await fs.rmdir(credentialsDir).catch(() => {});
|
await fs.rm(credentialsDir, { force: true, recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`SMB volume at ${path} mounted successfully.`);
|
logger.info(`SMB volume at ${path} mounted successfully.`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue