From 2187381db400a492e9080ad4f34da06ae4330346 Mon Sep 17 00:00:00 2001 From: FTCHD Date: Tue, 28 Jan 2025 13:25:04 +0200 Subject: [PATCH] move umount --- lib/rclone/mount.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/rclone/mount.ts b/lib/rclone/mount.ts index 0277fb7..9084b5f 100644 --- a/lib/rclone/mount.ts +++ b/lib/rclone/mount.ts @@ -1,10 +1,11 @@ import { downloadDir } from '@tauri-apps/api/path' -import { confirm } from '@tauri-apps/plugin-dialog' +import { ask, confirm } from '@tauri-apps/plugin-dialog' import { exists, writeFile } from '@tauri-apps/plugin-fs' import { fetch } from '@tauri-apps/plugin-http' import { revealItemInDir } from '@tauri-apps/plugin-opener' import { platform } from '@tauri-apps/plugin-os' import { exit } from '@tauri-apps/plugin-process' +import { Command } from '@tauri-apps/plugin-shell' export async function needsMountPlugin() { const currentPlatform = platform() @@ -72,3 +73,33 @@ export async function dialogGetMountPlugin() { } } } + +export async function unmountRemote(mountPoint: string, force = false) { + const command = Command.create('umount', [force ? '-f' : '', mountPoint]) + + const output = await command.execute() + + // console.log('output') + // console.log(JSON.stringify(output, null, 2)) + + if (output.code !== 0) { + if (output.stderr.toLowerCase().includes('busy')) { + const answer = await ask('This resource is busy, do you want to force unmount?', { + title: 'Could not unmount', + kind: 'warning', + }) + if (answer) { + return await unmountRemote(mountPoint, true) + } + throw new Error(output.stderr) + } + + if (output.stderr.toLowerCase().includes('not currently mounted')) { + return + } + + throw new Error(output.stderr) + } + + return +}