Skip to content

fix(storage): Fixed an issue with the SFTP path history#1077

Merged
GT-610 merged 2 commits intolollipopkit:mainfrom
GT-610:main
Mar 19, 2026
Merged

fix(storage): Fixed an issue with the SFTP path history#1077
GT-610 merged 2 commits intolollipopkit:mainfrom
GT-610:main

Conversation

@GT-610
Copy link
Copy Markdown
Collaborator

@GT-610 GT-610 commented Mar 19, 2026

Resolve #1030.

Added path validity checks when processing the SFTP path history

Standardized the format of stored paths and removed extra slashes

Summary by CodeRabbit

  • Bug Fixes
    • Validate and verify previously opened SFTP paths before auto-loading to avoid loading deleted or inaccessible locations; failures are now handled gracefully.
    • Normalize and store path history to remove duplicate consecutive slashes for consistent behavior and more reliable path recovery.

Added path validity checks when processing the SFTP path history

Standardized the format of stored paths and removed extra slashes
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b4651372-fb87-4ecc-accc-d30842f0d314

📥 Commits

Reviewing files that changed from the base of the PR and between 5784e0b and 0e60131.

📒 Files selected for processing (1)
  • lib/view/page/storage/sftp.dart

📝 Walkthrough

Walkthrough

The PR normalizes SFTP paths (collapsing repeated / into a single /) and adds a helper _normalizeSftpPath(String). On startup (afterFirstLayout), when restoring the last path, it normalizes the stored path, creates a temporary SFTP client, verifies the path by calling sftp.listdir(normalizedHistory), assigns initPath only if verification succeeds, and closes the temporary client while suppressing errors. _listDir now persists the normalized path into history.

Possibly related PRs

  • PR 1019: Also modifies lib/view/page/storage/sftp.dart's startup path logic and history handling, including remote-home detection and fallback.
  • PR 993: Changes SFTP path handling in the same file, addressing platform-specific separator handling and local-path joining.
🚥 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 pull request title 'fix(storage): Fixed an issue with the SFTP path history' clearly describes the main change: fixing an SFTP path history issue through path normalization and validation.
Linked Issues check ✅ Passed The pull request successfully addresses issue #1030 by normalizing SFTP paths (removing extra slashes) and adding path validity checks, which prevents the 'No such file' errors during rename operations.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #1030: path normalization in history persistence, path validation when loading history, and the helper method for path normalization are all in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5784e0bd06

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +103 to +104
final sftp = await _client.sftp();
await sftp.listdir(history);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reuse or close the validation SFTP session

When sftpOpenLastPath is enabled and a history entry exists, this opens a fresh SftpClient just to run listdir(history) and then drops it. In dartssh2, SSHClient.sftp() opens a new SFTP session, and _listDir() later uses _status.client/_client.sftp() for the real browse session, so the instance created here is neither reused nor closed. Re-entering the SFTP page a few times on the same SSH connection can therefore accumulate orphaned channels until the server starts rejecting new SFTP work.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/view/page/storage/sftp.dart (1)

647-651: Use a shared path-normalization helper here for consistency.

This loop works, but sharing a single normalization helper with the restore path avoids duplicated logic and keeps canonicalization behavior consistent.

Refactor snippet
-            var normalizedPath = listPath;
-            while (normalizedPath.contains('//')) {
-              normalizedPath = normalizedPath.replaceAll('//', '/');
-            }
+            final normalizedPath = _normalizeSftpPath(listPath);
             Stores.history.sftpLastPath.put(widget.args.spi.id, normalizedPath);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/view/page/storage/sftp.dart` around lines 647 - 651, The loop that
collapses duplicate slashes for normalizedPath (starting from listPath) should
be replaced with the shared path-normalization helper used elsewhere (the same
helper used for the restore path) to avoid duplicated logic and keep
canonicalization consistent; locate the code around normalizedPath/listPath and
replace the manual while-replaceAll logic with a call to the common helper
(e.g., normalizePath or canonicalizePath) before calling
Stores.history.sftpLastPath.put(widget.args.spi.id, normalizedPath).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/view/page/storage/sftp.dart`:
- Around line 102-105: The stored raw path from
Stores.history.sftpLastPath.fetch(...) must be normalized before validation and
assignment: retrieve the fetched value, normalize it to collapse duplicate
slashes and remove trailing slash (except root) (e.g., use the app's
path-normalization helper or implement simple normalization), then call await
_client.sftp() and await sftp.listdir(normalizedPath) to validate; only on
successful validation assign initPath = normalizedPath instead of the raw
fetched value.

---

Nitpick comments:
In `@lib/view/page/storage/sftp.dart`:
- Around line 647-651: The loop that collapses duplicate slashes for
normalizedPath (starting from listPath) should be replaced with the shared
path-normalization helper used elsewhere (the same helper used for the restore
path) to avoid duplicated logic and keep canonicalization consistent; locate the
code around normalizedPath/listPath and replace the manual while-replaceAll
logic with a call to the common helper (e.g., normalizePath or canonicalizePath)
before calling Stores.history.sftpLastPath.put(widget.args.spi.id,
normalizedPath).
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 426da587-fa6e-49a8-bca9-d72a6d62cb27

📥 Commits

Reviewing files that changed from the base of the PR and between e8265bc and 5784e0b.

📒 Files selected for processing (1)
  • lib/view/page/storage/sftp.dart

…management

Extract path normalization logic into a separate method: _normalizeSftpPath
Ensure that the SFTP client is properly closed after use
@GT-610 GT-610 merged commit 728116e into lollipopkit:main Mar 19, 2026
1 check passed
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.

try rename php file: SftpStatusError: No such file(code 2)

1 participant