Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise file move #522

Merged
merged 2 commits into from
Dec 22, 2024
Merged

Optimise file move #522

merged 2 commits into from
Dec 22, 2024

Conversation

sahinfalcon
Copy link
Contributor

This fixes #467, now when moving files within the same partition, os.Rename is used to update inode pointers instead of copying data. This significantly improves performance for large files and maintains atomic operations where possible.

Copy link

netlify bot commented Dec 20, 2024

Deploy Preview for superfile canceled.

Name Link
🔨 Latest commit 6f1be2f
🔍 Latest deploy log https://app.netlify.com/sites/superfile/deploys/676560faa1617a0008e0b1df

@yorukot yorukot merged commit a24093b into yorukot:main Dec 22, 2024
4 checks passed
@yorukot
Copy link
Owner

yorukot commented Dec 22, 2024

Thanks a lot for your contribution!

@sahinfalcon
Copy link
Contributor Author

sahinfalcon commented Dec 22, 2024

Happy to contribute 😄

@sahinfalcon sahinfalcon deleted the optimise-file-move branch December 22, 2024 17:16
@booth-w
Copy link
Contributor

booth-w commented Dec 23, 2024

Oh wow. Thank you. This was the only thing missing that stopped me from fully switching to this as my file manager.

@yorukot
Copy link
Owner

yorukot commented Jan 6, 2025

The changes in this PR cause build failures on Windows Issue #534. To address this problem, I've implemented a cross-platform solution to ensure compatibility. Below is the updated function:

// isSamePartition checks if two paths are on the same filesystem partition
func isSamePartition(path1, path2 string) (bool, error) {
	// Get the absolute path to handle relative paths
	absPath1, err := filepath.Abs(path1)
	if err != nil {
		return false, fmt.Errorf("failed to get absolute path of the first path: %v", err)
	}

	absPath2, err := filepath.Abs(path2)
	if err != nil {
		return false, fmt.Errorf("failed to get absolute path of the second path: %v", err)
	}

	if runtime.GOOS == "windows" {
		// On Windows, we can check if both paths are on the same drive (same letter)
		drive1 := getDriveLetter(absPath1)
		drive2 := getDriveLetter(absPath2)
		return drive1 == drive2, nil
	}

	// For Unix-like systems, we use the same path to check the root partition
	return filepath.VolumeName(absPath1) == filepath.VolumeName(absPath2), nil
}

// getDriveLetter extracts the drive letter from a Windows path
func getDriveLetter(path string) string {
	// Windows paths are usually like "C:\path\to\file"
	// So we need to extract the drive letter (e.g., "C")
	return strings.ToUpper(string(path[0]))
}

If you have further suggestions or need clarification, feel free to let me know! Looking forward to your feedback!

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jan 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [yorukot/superfile](https://github.com/yorukot/superfile) | patch | `v1.1.6` -> `v1.1.7` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>yorukot/superfile (yorukot/superfile)</summary>

### [`v1.1.7`](https://github.com/yorukot/superfile/blob/HEAD/changelog.md#v117)

[Compare Source](yorukot/superfile@v1.1.6...v1.1.7)

> 2024-01-05

##### Update

-   OneDark Theme added [`#477`](yorukot/superfile#477)
-   Add keys PageUp and PageDown for better navigation [`#498`](yorukot/superfile#498)
-   Add hotkey for copying PWD to clipboard [`#510`](yorukot/superfile#510)
-   Add desktop entry [`#501`](yorukot/superfile#501)
-   Enable cd_on_quit when current directory is home directory [`#518`](yorukot/superfile#518)
-   Edit superfile config [`#509`](yorukot/superfile#509)

##### Bug fix

-   Fix rendering directory symlinks as directories, not files [`#481`](yorukot/superfile#481)
-   Fix opening files on Windows [`#496`](yorukot/superfile#496)
-   Fix lag in dotfile toggle with multiple panels [`#499`](yorukot/superfile#499)
-   Fix parent directory navigation on Windows [`#502`](yorukot/superfile#502)
-   Fix panic when deleting last file in directory [`#529`](yorukot/superfile#529)
-   Fix panic when scrolling through an empty metadata list [`#531`](yorukot/superfile#531)
-   Fix panic when trying to get folder size without needed permissions [`#532`](yorukot/superfile#532)
-   Fix lag when navigating directories with large image files [`#525`](yorukot/superfile#525)
-   Fix typo in welcome message [`#494`](yorukot/superfile#494)

##### Optimization

-   Optimize file move operation [`#522`](yorukot/superfile#522)
-   Optimize file extraction [`#524`](yorukot/superfile#524)
-   Warn overwrite when renaming files [`#526`](yorukot/superfile#526)
-   Work without trash [`#527`](yorukot/superfile#527)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45MC40IiwidXBkYXRlZEluVmVyIjoiMzkuOTAuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
@sahinfalcon sahinfalcon restored the optimise-file-move branch January 6, 2025 22:55
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.

Move files by only changing pointer data if both paths are in the same partition
3 participants