Changeset 4443

Show
Ignore:
Timestamp:
01/27/07 15:28:10 (2 years ago)
Author:
morris
Message:

If the file names differ in case only, move to a temporary file first, to solve problems with case-insensitive HFS+ file systems

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wired/trunk/NEWS

    r4365 r4443  
    441.3.2 
    55- Fix a problem with posting longer news posts 
     6- Fix a problem with renaming files when changing case only 
    67 
    781.3.1 
  • wired/trunk/wired/files.c

    r4426 r4443  
    433433wi_boolean_t wd_files_move_path(wi_string_t *frompath, wi_string_t *topath) { 
    434434        wi_array_t                      *array; 
    435         wi_string_t                     *component, *realfrompath, *realtopath; 
     435        wi_string_t                     *realfrompath, *realtopath; 
     436        wi_string_t                     *realfromname, *realtoname; 
     437        wi_string_t                     *path; 
    436438        struct stat                     sb; 
    437         wi_boolean_t            result = false
     439        wi_boolean_t            result
    438440         
    439441        realfrompath    = wd_files_real_path(frompath); 
    440442        realtopath              = wd_files_real_path(topath); 
    441         component               = wi_string_last_path_component(realfrompath); 
     443        realfromname    = wi_string_last_path_component(realfrompath); 
     444        realtoname              = wi_string_last_path_component(realtopath); 
    442445 
    443446        wi_string_delete_last_path_component(realfrompath); 
    444447        wi_string_resolve_aliases_in_path(realfrompath); 
    445448        wi_string_resolve_aliases_in_path(realtopath); 
    446         wi_string_append_path_component(realfrompath, component); 
     449        wi_string_append_path_component(realfrompath, realfromname); 
    447450         
    448451        if(!wi_file_lstat(realfrompath, &sb)) { 
     
    453456        } 
    454457 
    455         if(wi_file_lstat(realtopath, &sb)) { 
    456                 wd_reply(521, WI_STR("File or Directory Exists")); 
    457  
    458                 return false; 
    459         } 
    460          
    461         result = wi_file_rename(realfrompath, realtopath); 
     458        if(wi_string_case_insensitive_compare(realfromname, realtoname) == 0) { 
     459                path = wi_file_temporary_path_with_prefix_in_directory( 
     460                        wi_string_with_format(WI_STR(".%@"), realfromname), 
     461                        wi_string_by_deleting_last_path_component(realfrompath)); 
     462                 
     463                result = wi_file_rename(realfrompath, path); 
     464                 
     465                if(result) 
     466                        result = wi_file_rename(path, realtopath); 
     467        } else { 
     468                if(wi_file_lstat(realtopath, &sb)) { 
     469                        wd_reply(521, WI_STR("File or Directory Exists")); 
     470 
     471                        return false; 
     472                } 
     473                 
     474                result = wi_file_rename(realfrompath, realtopath); 
     475        } 
    462476         
    463477        if(result) {