@@ -1859,7 +1859,8 @@ contains |
| 1859 | ! Execute file/directory rename | 1859 | ! Execute file/directory rename |
| 1860 | character(len=*), intent(in) :: old_path, new_name | 1860 | character(len=*), intent(in) :: old_path, new_name |
| 1861 | character(len=1024) :: dirname, new_path, command, old_path_lower, new_path_lower | 1861 | 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 |
| 1863 | logical :: file_exists, case_only_change | 1864 | logical :: file_exists, case_only_change |
| 1864 | | 1865 | |
| 1865 | ! Validate new name | 1866 | ! Validate new name |
@@ -1885,12 +1886,40 @@ contains |
| 1885 | end if | 1886 | end if |
| 1886 | | 1887 | |
| 1887 | ! Check if this is a case-only change (for case-insensitive filesystems like macOS) | 1888 | ! Check if this is a case-only change (for case-insensitive filesystems like macOS) |
| 1888 | - old_path_lower = old_path | 1889 | + ! Extract just the basename (filename) for comparison to avoid path prefix issues |
| 1889 | - new_path_lower = new_path | 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 |
| 1890 | call to_lowercase(old_path_lower) | 1908 | call to_lowercase(old_path_lower) |
| 1891 | call to_lowercase(new_path_lower) | 1909 | call to_lowercase(new_path_lower) |
| 1892 | case_only_change = (trim(old_path_lower) == trim(new_path_lower)) | 1910 | case_only_change = (trim(old_path_lower) == trim(new_path_lower)) |
| 1893 | | 1911 | |
| | 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 | + |
| 1894 | ! Check if new path already exists (skip check for case-only changes) | 1923 | ! Check if new path already exists (skip check for case-only changes) |
| 1895 | if (.not. case_only_change) then | 1924 | if (.not. case_only_change) then |
| 1896 | inquire(file=trim(new_path), exist=file_exists) | 1925 | inquire(file=trim(new_path), exist=file_exists) |