99 "os"
1010 "path/filepath"
1111 "regexp"
12+ "runtime"
1213 "slices"
1314 "sort"
1415 "strconv"
@@ -21,18 +22,87 @@ import (
2122)
2223
2324// Check if the directory is external disk path
25+ // Todo : This function should be give two directories, and it should return
26+ // if the two share a different disk partition.
27+ // Ideally we shouldn't even try to figure that out in our file operations, and let OS handles it.
28+ // But at least right now its not okay. This returns if `path` is an External disk
29+ // from perspective of `/`, but it should tell from perspective of currently open directory
30+ // The usage of this function in cut/paste is not as expected.
2431func isExternalDiskPath (path string ) bool {
25- dir := filepath .Dir (path )
32+ // This is very vague. You cannot tell if a path is belonging to an external partition
33+ // if you dont define the source path to compare with
34+ // But making this true will cause slow file operations based on current implementation
35+ if runtime .GOOS == "windows" {
36+ return false
37+ }
38+
39+ // exclude timemachine on MacOS
40+ if strings .HasPrefix (path , "/Volumes/.timemachine" ) {
41+ return false
42+ }
43+
44+ // to filter out mounted partitions like /, /boot etc
45+ return strings .HasPrefix (path , "/mnt" ) ||
46+ strings .HasPrefix (path , "/media" ) ||
47+ strings .HasPrefix (path , "/run/media" ) ||
48+ strings .HasPrefix (path , "/Volumes" )
49+ }
50+
51+ func shouldListDisk (mountPoint string ) bool {
52+ if runtime .GOOS == "windows" {
53+ // We need to get C:, D: drive etc in the list
54+ return true
55+ }
2656
27- // exclude timemachine
28- if strings .HasPrefix (dir , "/Volumes/.timemachine" ) {
57+ // Should always list the main disk
58+ if mountPoint == "/" {
59+ return true
60+ }
61+
62+ // Todo : make a configurable field in config.yaml
63+ // excluded_disk_mounts = ["/Volumes/.timemachine"]
64+ // Mountpoints that are in subdirectory of disk_mounts
65+ // but still are to be excluded in disk section of sidebar
66+ if strings .HasPrefix (mountPoint , "/Volumes/.timemachine" ) {
2967 return false
3068 }
3169
32- return strings .HasPrefix (dir , "/mnt" ) ||
33- strings .HasPrefix (dir , "/media" ) ||
34- strings .HasPrefix (dir , "/run/media" ) ||
35- strings .HasPrefix (dir , "/Volumes" )
70+ // We avoid listing all mounted partitions (Otherwise listed disk could get huge)
71+ // but only a few partitions that usually corresponds to external physical devices
72+ // For example : mounts like /boot, /var/ will get skipped
73+ // This can be inaccurate based on your system setup if you mount any external devices
74+ // on other directories, or if you have some extra mounts on these directories
75+ // Todo : make a configurable field in config.yaml
76+ // disk_mounts = ["/mnt", "/media", "/run/media", "/Volumes"]
77+ // Only block devicies that are mounted on these or any subdirectory of these Mountpoints
78+ // Will be shown in disk sidebar
79+ return strings .HasPrefix (mountPoint , "/mnt" ) ||
80+ strings .HasPrefix (mountPoint , "/media" ) ||
81+ strings .HasPrefix (mountPoint , "/run/media" ) ||
82+ strings .HasPrefix (mountPoint , "/Volumes" )
83+ }
84+
85+ func diskName (mountPoint string ) string {
86+ // In windows we dont want to use filepath.Base as it returns "\" for when
87+ // mountPoint is any drive root "C:", "D:", etc. Hence causing same name
88+ // for each drive
89+ if runtime .GOOS == "windows" {
90+ return mountPoint
91+ }
92+
93+ // This might cause duplicate names in case you mount two devices in
94+ // /mnt/usb and /mnt/dir2/usb . Full mountpoint is a more accurate way
95+ // but that results in messy UI, hence we do this.
96+ return filepath .Base (mountPoint )
97+ }
98+
99+ func diskLocation (mountPoint string ) string {
100+ // In windows if you are in "C:\some\path", "cd C:" will not cd to root of C: drive
101+ // but "cd C:\" will
102+ if runtime .GOOS == "windows" {
103+ return filepath .Join (mountPoint , "\\ " )
104+ }
105+ return mountPoint
36106}
37107
38108func returnFocusType (focusPanel focusPanelType ) filePanelFocusType {
0 commit comments