Skip to content

Commit a1b17a7

Browse files
IIIsengardclaude
andcommitted
fix: report a failed CLI unmount and failed remounts
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 13a9ed3 commit a1b17a7

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ changes (e.g. `settings.json` shape changes that need a migration).
3232
another account could create it first and answer your scripts.
3333

3434
### Fixed
35+
- `--unmount` now reports a failure when another rclone process still holds the
36+
drive, instead of saying it was unmounted.
37+
- The message after renaming a remote counts only the drives that came back.
3538
- **Changes made in quick succession are saved correctly.** When two saves overlapped, the
3639
settings file could get half-finished changes or the save could fail, and a mount running
3740
on a temporary drive letter could show the wrong letter.

‎src/RcloneMount/MainForm.Cli.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ private CliRelay.Response BuildListReply()
164164

165165
KeepUnmounted(found);
166166

167+
(string Letter, bool StillMounted) stopped;
167168
try
168169
{
169-
await StopMountAsync(found);
170+
stopped = await StopMountAsync(found);
170171
}
171172
catch (Exception ex)
172173
{
@@ -176,9 +177,13 @@ private CliRelay.Response BuildListReply()
176177
try { RefreshMountList(); }
177178
catch { }
178179

179-
return new CliRelay.Response(0, $"Unmounted '{found.RemoteName}'.");
180+
return UnmountReply(found.RemoteName, stopped.Letter, stopped.StillMounted);
180181
}
181182

183+
internal static CliRelay.Response UnmountReply(string name, string live, bool stillMounted) => stillMounted
184+
? new CliRelay.Response(5, $"{live} is still mounted by another rclone process (not started by this app).")
185+
: new CliRelay.Response(0, $"Unmounted '{name}'.");
186+
182187
private Mount? FindMountByName(string name)
183188
{
184189
if (string.IsNullOrWhiteSpace(name)) return null;

‎src/RcloneMount/MainForm.RemoteOps.cs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,8 @@ private async void BtnEditRemote_Click(object? sender, EventArgs e)
407407
editor.ResultValues, editor.KeysToPrune);
408408

409409
SetStatus(renamed
410-
? (mountsToRemount.Count > 0
411-
? $"Renamed to {newName}, {mountsToRemount.Count} mount(s) remounted."
412-
: $"Renamed to {newName} and updated.")
410+
? RenameStatus(newName, mountsToRemount.Count,
411+
mountsToRemount.Count(m => mountService?.IsMounted(m) == true))
413412
: $"Updated remote {newName}.");
414413
if (pruneNote is not null)
415414
activityLog.Warn(pruneNote);
@@ -421,6 +420,11 @@ private async void BtnEditRemote_Click(object? sender, EventArgs e)
421420
}
422421
}
423422

423+
internal static string RenameStatus(string newName, int unmounted, int back) =>
424+
unmounted == 0 ? $"Renamed to {newName} and updated."
425+
: back == unmounted ? $"Renamed to {newName}, {back} mount(s) remounted."
426+
: $"Renamed to {newName}, {back} of {unmounted} mount(s) remounted. See the activity log.";
427+
424428
// Saves an edit, renaming first when the name changed, with the running mounts down around a
425429
// rename. Whatever fails, they come back up, under the name rclone.conf then holds.
426430
// Returns the note about settings that could not be removed.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace RcloneMount.Tests;
2+
3+
// Messages must not claim something happened when it did not.
4+
public class ResultMessageTests
5+
{
6+
[Fact]
7+
public void CliUnmount_OfADriveAnotherProcessStillHolds_IsAFailure()
8+
{
9+
var reply = MainForm.UnmountReply("media", "M:", stillMounted: true);
10+
11+
Assert.Equal(5, reply.ExitCode);
12+
Assert.Contains("M: is still mounted", reply.Message);
13+
}
14+
15+
[Fact]
16+
public void CliUnmount_OfAGoneDrive_Succeeds()
17+
{
18+
var reply = MainForm.UnmountReply("media", "M:", stillMounted: false);
19+
20+
Assert.Equal(0, reply.ExitCode);
21+
Assert.Equal("Unmounted 'media'.", reply.Message);
22+
}
23+
24+
[Theory]
25+
[InlineData(0, 0, "Renamed to new and updated.")]
26+
[InlineData(2, 2, "Renamed to new, 2 mount(s) remounted.")]
27+
[InlineData(2, 1, "Renamed to new, 1 of 2 mount(s) remounted. See the activity log.")]
28+
public void Rename_CountsOnlyTheDrivesThatCameBack(int unmounted, int back, string expected) =>
29+
Assert.Equal(expected, MainForm.RenameStatus("new", unmounted, back));
30+
}

0 commit comments

Comments
 (0)