fortrangoingonforty/fuss / a216105

Browse files

fix some renames not respecting casing

Authored by espadonne
SHA
a216105212ef42cee14abd4701d9c4d252f47cc4
Parents
bc6560b
Tree
940ae0d

1 changed file

StatusFile+-
M src/fuss_main.f90 32 3
src/fuss_main.f90modified
@@ -1859,7 +1859,8 @@ contains
18591859
         ! Execute file/directory rename
18601860
         character(len=*), intent(in) :: old_path, new_name
18611861
         character(len=1024) :: dirname, new_path, command, old_path_lower, new_path_lower
1862
-        integer :: status, last_slash
1862
+        character(len=1024) :: old_basename, new_basename
1863
+        integer :: status, last_slash, old_last_slash, new_last_slash
18631864
         logical :: file_exists, case_only_change
18641865
 
18651866
         ! Validate new name
@@ -1885,12 +1886,40 @@ contains
18851886
         end if
18861887
 
18871888
         ! Check if this is a case-only change (for case-insensitive filesystems like macOS)
1888
-        old_path_lower = old_path
1889
-        new_path_lower = new_path
1889
+        ! Extract just the basename (filename) for comparison to avoid path prefix issues
1890
+        old_last_slash = index(old_path, '/', back=.true.)
1891
+        new_last_slash = index(new_path, '/', back=.true.)
1892
+
1893
+        if (old_last_slash > 0) then
1894
+            old_basename = old_path(old_last_slash+1:)
1895
+        else
1896
+            old_basename = old_path
1897
+        end if
1898
+
1899
+        if (new_last_slash > 0) then
1900
+            new_basename = new_path(new_last_slash+1:)
1901
+        else
1902
+            new_basename = new_path
1903
+        end if
1904
+
1905
+        ! Now compare the basenames in lowercase
1906
+        old_path_lower = old_basename
1907
+        new_path_lower = new_basename
18901908
         call to_lowercase(old_path_lower)
18911909
         call to_lowercase(new_path_lower)
18921910
         case_only_change = (trim(old_path_lower) == trim(new_path_lower))
18931911
 
1912
+        ! Debug logging
1913
+        open(99, file='/tmp/fuss_debug.log', position='append')
1914
+        write(99, '(A,A)') 'RENAME: old_path = ', trim(old_path)
1915
+        write(99, '(A,A)') 'RENAME: new_path = ', trim(new_path)
1916
+        write(99, '(A,A)') 'RENAME: old_basename = ', trim(old_basename)
1917
+        write(99, '(A,A)') 'RENAME: new_basename = ', trim(new_basename)
1918
+        write(99, '(A,A)') 'RENAME: old_path_lower = ', trim(old_path_lower)
1919
+        write(99, '(A,A)') 'RENAME: new_path_lower = ', trim(new_path_lower)
1920
+        write(99, '(A,L)') 'RENAME: case_only_change = ', case_only_change
1921
+        close(99)
1922
+
18941923
         ! Check if new path already exists (skip check for case-only changes)
18951924
         if (.not. case_only_change) then
18961925
             inquire(file=trim(new_path), exist=file_exists)