Skip to content

fix(fs): file transfer, reconnect, restore dir#41

Open
fufesou wants to merge 3 commits into
masterfrom
fix/file-transfer-reconnect-dir
Open

fix(fs): file transfer, reconnect, restore dir#41
fufesou wants to merge 3 commits into
masterfrom
fix/file-transfer-reconnect-dir

Conversation

@fufesou

@fufesou fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved startup directory resolution: the app tries multiple candidate locations (current, saved, home) in order, opens the first available, and will retry after reconnect delays if none succeed.
    • More reliable navigation: parent/back, refresh, and open operations now surface success/failure and run asynchronously to prevent the file dialog from hanging.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

FileController.onReady builds a de-duplicated, ordered candidate list of directories (current path, saved peer dir, home) and sequentially attempts to open each until one succeeds, retrying after reconnect delay if none do. Navigation methods now return Future<bool>; parent logic moved to _goToParentDirectory and public call is fire-and-forget.

Changes

Cohort / File(s) Summary
FileController startup & navigation
flutter/lib/models/file_model.dart
onReady builds an ordered, de-duplicated candidate list and iteratively calls a new _openDirectoryPath(...) -> Future<bool> until one succeeds; if none succeed it retries after reconnect delay. refresh() and openDirectory(...) now return Future<bool>; "." delegates to refresh(), ".." handled via new _goToParentDirectory(...). _openDirectoryPath centralizes directory load and returns false on exceptions (logged). Public goToParentDirectory() invokes the async parent helper via unawaited(...).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hop through paths both near and far,
Trying each door until one sticks like tar.
Back to parent, home, or a saved nest,
I search and settle where the files rest.
✨🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(fs): file transfer, reconnect, restore dir' directly relates to the main changes: improving directory opening behavior on file transfer reconnection and restoring saved directory paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/file-transfer-reconnect-dir

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/models/file_model.dart`:
- Around line 410-415: The logic now uses directory.value.path as currentPath
causing a stale path to be preferred and preventing the later home fallback if
openDirectory fails; change selectFileControllerReadyPath/openDirectory usage so
you first determine a safe path (fall back to savedDir or options.value.home
when directory.value.path looks stale) and/or handle openDirectory failures by
awaiting its result and, on error, calling openDirectory with options.value.home
(or re-run the savedDir fallback) so the file panel isn't left stuck; touch the
selectFileControllerReadyPath invocation and the openDirectory call to add the
fallback/error handling around directory.value.path, savedDir, and
options.value.home.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 22348bf3-ddf8-493d-8a43-8c7fb4910273

📥 Commits

Reviewing files that changed from the base of the PR and between ee8cc0c and 3826a6b.

📒 Files selected for processing (1)
  • flutter/lib/models/file_model.dart

Comment thread flutter/lib/models/file_model.dart Outdated
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from 3826a6b to aeea19f Compare April 28, 2026 06:07
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Improves the file manager’s initial directory restore/selection flow by trying multiple candidate directories (current, saved, home) and using an openDirectory success/failure result to decide which to keep.

Changes:

  • Add helper to build an ordered list of candidate directories to open on controller ready.
  • Update onReady() to attempt opening current/saved/home paths until one succeeds.
  • Change openDirectory, refresh, and goToParentDirectory to return Future<bool> indicating success.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flutter/lib/models/file_model.dart Outdated
Comment thread flutter/lib/models/file_model.dart Outdated
Comment thread flutter/lib/models/file_model.dart Outdated
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from aeea19f to b38454c Compare April 28, 2026 07:15
@fufesou fufesou requested a review from Copilot April 28, 2026 07:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flutter/lib/models/file_model.dart Outdated
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from b38454c to 0e08942 Compare April 28, 2026 07:32
@fufesou fufesou requested a review from Copilot April 28, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flutter/lib/models/file_model.dart
Comment thread flutter/lib/models/file_model.dart Outdated
Comment thread flutter/lib/models/file_model.dart Outdated
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from 0e08942 to f076bb5 Compare April 28, 2026 07:55
@fufesou fufesou requested a review from Copilot April 28, 2026 07:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flutter/lib/models/file_model.dart
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from f076bb5 to 957158c Compare April 28, 2026 08:13
@fufesou fufesou requested a review from Copilot April 28, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flutter/lib/models/file_model.dart
Comment thread flutter/lib/models/file_model.dart
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/models/file_model.dart`:
- Around line 50-70: The helper _selectFileControllerReadyPaths currently always
adds homePath even when empty, causing openDirectory("") and duplicate retry
attempts; change _selectFileControllerReadyPaths to only add homePath when it is
not empty (same guard as for currentPath/savedPath), and also update the
retry/enqueue logic that calls openDirectory (referenced around the retry block
that checks lines ~433-435) to skip enqueuing or retrying when homePath is empty
so openDirectory("") is never attempted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2677141c-2116-4b21-b1e2-caff13fcc1f7

📥 Commits

Reviewing files that changed from the base of the PR and between 957158c and 38e22c6.

📒 Files selected for processing (1)
  • flutter/lib/models/file_model.dart

Comment thread flutter/lib/models/file_model.dart Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

flutter/lib/models/file_model.dart:479

  • pushHistory() is called before verifying the directory open succeeds. If fetchDirectory() throws, directory.value.path stays unchanged but history still records it, and subsequent goBack() will pop the current path (and potentially clear additional history entries due to the directory.value.path == path recursion). Consider only pushing history after a successful open (or reverting the push when returning false).
    if (!isBack) {
      pushHistory();
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from 38e22c6 to 8330b59 Compare April 29, 2026 03:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/models/file_model.dart`:
- Around line 505-517: The public method goToParentDirectory currently discards
the result by calling unawaited(_goToParentDirectory()); change
goToParentDirectory to return Future<bool> and return/await the underlying
_goToParentDirectory({bool isBack = false}) so callers can observe
success/failure; update any callers to await the Future<bool> and handle a false
return (or propagate) instead of assuming success; reference functions:
goToParentDirectory, _goToParentDirectory, and openDirectory.
- Around line 394-412: The reconnect logic currently attempts opening
directory.value.path, savedDir, and options.value.home once before a 1s delay
and if none opened only retries options.value.home; change it so after the delay
you retry the saved/current directories too: preserve savedDir and
directory.value.path (from bind.sessionGetPeerOption and directory.value.path),
and if opened is still false after the delay call openDirectory for
directory.value.path and savedDir (in that order) before falling back to calling
openDirectory(options.value.home, isBack: true); ensure you keep using the
existing openDirectory function and the opened flag so the first successful open
short-circuits further attempts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 403227a1-54c3-427f-bb8e-59096d74cc31

📥 Commits

Reviewing files that changed from the base of the PR and between 38e22c6 and 8330b59.

📒 Files selected for processing (1)
  • flutter/lib/models/file_model.dart

Comment thread flutter/lib/models/file_model.dart Outdated
Comment thread flutter/lib/models/file_model.dart Outdated
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from 8330b59 to a9dd267 Compare April 29, 2026 03:44
Signed-off-by: fufesou <linlong1266@gmail.com>
@fufesou fufesou force-pushed the fix/file-transfer-reconnect-dir branch from a9dd267 to 0812f80 Compare April 29, 2026 04:19
Signed-off-by: fufesou <linlong1266@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
flutter/lib/models/file_model.dart (1)

464-485: ⚠️ Potential issue | 🟠 Major

Record history only after a directory open succeeds.

pushHistory() runs before fetchDirectory(). If the open fails, the stale entry stays on the stack and later goBack() calls can skip or drop entries, leaving navigation in a bad state after a typo or reconnect failure.

Proposed fix
   Future<bool> _openDirectoryPath(String path, {bool isBack = false}) async {
-    if (!isBack) {
-      pushHistory();
-    }
     final showHidden = options.value.showHidden;
     final isWindows = options.value.isWindows;
@@
     try {
       final fd = await fileFetcher.fetchDirectory(path, isLocal, showHidden);
       fd.format(isWindows, sort: sortBy.value);
+      if (!isBack) {
+        pushHistory();
+      }
       directory.value = fd;
       return true;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flutter/lib/models/file_model.dart` around lines 464 - 485, The current
_openDirectoryPath calls pushHistory() before attempting fetchDirectory(), which
records a history entry even when opening fails; move the pushHistory() call so
it runs only after fetchDirectory succeeds (i.e., after obtaining and formatting
fd but before updating directory.value), and preserve the conditional on isBack
so history is only pushed when !isBack; keep the existing try/catch and error
logging around fetchDirectory and do not change the failure path so no history
is recorded on error.
♻️ Duplicate comments (1)
flutter/lib/models/file_model.dart (1)

396-417: ⚠️ Potential issue | 🟡 Minor

Guard the empty home path in the retry candidate list.

options.value.home is still inserted unconditionally, so an empty string can still reach _openDirectoryPath("") on the first pass and the delayed retry. This is the same empty-home-path issue reported earlier.

Proposed fix
       final dirs = <String>{
         if (directory.value.path.isNotEmpty) directory.value.path,
         if (savedDir.isNotEmpty) savedDir,
-        options.value.home,
+        if (options.value.home.isNotEmpty) options.value.home,
       };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flutter/lib/models/file_model.dart` around lines 396 - 417, The set of
candidate paths in tryOpenReadyDirs currently always includes options.value.home
which can be empty; update tryOpenReadyDirs to only insert options.value.home
when it is non-empty (e.g., guard with options.value.home.isNotEmpty) so
_openDirectoryPath is never called with an empty string; keep other candidates
(directory.value.path and savedDir) as-is so the delayed retry that calls
tryOpenReadyDirs() uses the same guarded candidate list.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@flutter/lib/models/file_model.dart`:
- Around line 464-485: The current _openDirectoryPath calls pushHistory() before
attempting fetchDirectory(), which records a history entry even when opening
fails; move the pushHistory() call so it runs only after fetchDirectory succeeds
(i.e., after obtaining and formatting fd but before updating directory.value),
and preserve the conditional on isBack so history is only pushed when !isBack;
keep the existing try/catch and error logging around fetchDirectory and do not
change the failure path so no history is recorded on error.

---

Duplicate comments:
In `@flutter/lib/models/file_model.dart`:
- Around line 396-417: The set of candidate paths in tryOpenReadyDirs currently
always includes options.value.home which can be empty; update tryOpenReadyDirs
to only insert options.value.home when it is non-empty (e.g., guard with
options.value.home.isNotEmpty) so _openDirectoryPath is never called with an
empty string; keep other candidates (directory.value.path and savedDir) as-is so
the delayed retry that calls tryOpenReadyDirs() uses the same guarded candidate
list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 04ea97bc-78ca-46c0-8aa1-884c6bf2618e

📥 Commits

Reviewing files that changed from the base of the PR and between 8330b59 and ea16bd2.

📒 Files selected for processing (1)
  • flutter/lib/models/file_model.dart

Signed-off-by: fufesou <linlong1266@gmail.com>
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.

2 participants