Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 23, 2025

Fixes issue where the mount button becomes disabled (grayed out) on macOS when the mount point directory exists, preventing users from mounting rclone remotes.

Problem

On macOS, users experienced incorrect mount button behavior:

  • When mount point directory doesn't exist: button enabled but mounting fails with "no such file or directory"
  • When mount point directory exists: button becomes disabled/grayed out, preventing mounting entirely
  • Manual rclone commands work correctly in both scenarios

Root Cause

The issue was in the get_mount_info_list function's mount status logic. When a directory exists but no rclone process is running, the status was incorrectly set to "unmounting":

// Problematic logic
} else if is_mounted {
    "unmounting"  // This disabled the mount button!
} else {
    "unmounted"
}

This caused isConfigMounting() to return true, which disables the mount button in the UI.

Solution

1. Fixed Mount Status Logic
Changed the logic so that when no rclone process is running, the status is always "unmounted" regardless of directory existence:

} else {
    // If process is not running, the mount point should be considered unmounted
    // regardless of whether the directory exists or not
    "unmounted"
}

2. Added Directory Creation
Enhanced the mount process creation to automatically create mount point directories when they don't exist:

// Extract mount point from args and create directory if it doesn't exist
let args_vec = split_args_vec(config.args.clone());
if args_vec.len() >= 2 {
    let mount_point = &args_vec[1];
    let mount_path = Path::new(mount_point);
    if !mount_path.exists() {
        if let Err(e) = fs::create_dir_all(mount_path) {
            return Err(format!("Failed to create mount point directory '{}': {}", mount_point, e));
        }
    }
}

Result

After this fix:

  • ✅ Mount button remains enabled when directory exists (primary issue resolved)
  • ✅ Mount button remains enabled when directory doesn't exist
  • ✅ Mounting succeeds in both cases (directory created automatically if needed)
  • ✅ Existing functionality for mounted/unmounted states unchanged

The changes are minimal and surgical, affecting only the problematic mount status determination and adding defensive directory creation without impacting other mount/unmount workflows.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@jyxjjj jyxjjj changed the title [WIP] 看下问题 #109 找找代码位置 提供修复建议 fix(mount): fix button status Sep 23, 2025
…ogic and add directory creation

Co-authored-by: jyxjjj <[email protected]>
@Copilot Copilot AI changed the title fix(mount): fix button status Fix mount button disabled incorrectly on macOS when directory exists (#109) Sep 23, 2025
Copilot finished work on behalf of jyxjjj September 23, 2025 03:07
@Copilot Copilot AI requested a review from jyxjjj September 23, 2025 03:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a macOS-specific issue where the mount button incorrectly becomes disabled when a mount point directory exists but no rclone process is running.

  • Fixed mount status logic to return "unmounted" when no rclone process is running, regardless of directory existence
  • Added automatic creation of mount point directories during the mount process
  • Optimized args parsing by reusing the parsed vector instead of calling split_args_vec twice

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +207 to +210
// Extract mount point from args and create directory if it doesn't exist
let args_vec = split_args_vec(config.args.clone());
if args_vec.len() >= 2 {
let mount_point = &args_vec[1]; // Mount point is typically the second argument
Copy link
Preview

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment assumes mount point is always the second argument, but this may not be accurate for all rclone mount command variations. Consider validating that the argument is actually a mount point path or documenting the specific expected command format.

Suggested change
// Extract mount point from args and create directory if it doesn't exist
let args_vec = split_args_vec(config.args.clone());
if args_vec.len() >= 2 {
let mount_point = &args_vec[1]; // Mount point is typically the second argument
// Extract mount point from args and create directory if it doesn't exist.
// The mount point is the first argument that does not start with a dash ('-'),
// after the remote name (which is typically the first positional argument).
let args_vec = split_args_vec(config.args.clone());
// Find the first argument that does not start with '-' and is not the remote name
let mount_point_opt = args_vec
.iter()
.filter(|arg| !arg.starts_with('-'))
.nth(1); // 0th is remote name, 1st is mount point
if let Some(mount_point) = mount_point_opt {

Copilot uses AI. Check for mistakes.

Comment on lines +209 to +210
if args_vec.len() >= 2 {
let mount_point = &args_vec[1]; // Mount point is typically the second argument
Copy link
Preview

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded index 1 for the mount point assumes a specific argument order. Consider using a more robust method to identify the mount point, such as checking for path-like arguments or using rclone's argument parsing patterns.

Suggested change
if args_vec.len() >= 2 {
let mount_point = &args_vec[1]; // Mount point is typically the second argument
// Find the first non-flag argument after the command (usually the mount point)
let mount_point_opt = args_vec.iter()
.skip(1) // skip the command itself (e.g., "mount")
.find(|arg| !arg.starts_with('-'));
if let Some(mount_point) = mount_point_opt {

Copilot uses AI. Check for mistakes.

@jyxjjj jyxjjj removed their request for review September 23, 2025 03:11
@jyxjjj jyxjjj changed the title Fix mount button disabled incorrectly on macOS when directory exists (#109) fix(mount): mount button disabled incorrectly on macOS when directory exists (#109) Sep 23, 2025
@jyxjjj jyxjjj linked an issue Sep 23, 2025 that may be closed by this pull request
3 tasks
@jyxjjj jyxjjj requested a review from elysia-best September 23, 2025 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[错误] Mac中rclone无法挂载
2 participants