Changeset 4377

Show
Ignore:
Timestamp:
09/20/06 17:59:35 (2 years ago)
Author:
morris
Message:

Abstract all path expansion to wr_files_full_paths


Make mv command move stuff into folders correctly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wire/trunk/wire/commands.c

    r4376 r4377  
    619619 
    620620static void wr_cmd_comment(wi_array_t *arguments) { 
     621        wi_array_t              *paths; 
    621622        wi_string_t             *path, *comment; 
    622623        uint32_t                i, count; 
     
    625626         
    626627        if(count == 1) { 
    627                 path = wr_files_full_path(WI_ARRAY(arguments, 0)); 
     628                paths = wr_files_full_paths(arguments); 
     629                count = wi_array_count(paths); 
    628630                comment = WI_STR(""); 
    629631 
    630                 wr_send_command(WI_STR("COMMENT %#@%c%#@"), 
    631                         path,           WR_FIELD_SEPARATOR, 
    632                         comment); 
    633         } else { 
    634                 comment = wi_array_last_data(arguments); 
    635                  
    636                 for(i = 0; i < count - 1; i++) { 
    637                         path = wr_files_full_path(WI_ARRAY(arguments, i)); 
     632                for(i = 0; i < count; i++) { 
     633                        path = WI_ARRAY(paths, i); 
    638634                         
    639635                        wr_send_command(WI_STR("COMMENT %#@%c%#@"), 
     
    641637                                comment); 
    642638                } 
     639        } else { 
     640                paths = wr_files_full_paths(wi_array_subarray_with_range(arguments, wi_make_range(0, wi_array_count(arguments) - 1))); 
     641                count = wi_array_count(paths); 
     642                comment = wi_array_last_data(arguments); 
     643                 
     644                for(i = 0; i < count; i++) { 
     645                        path = WI_ARRAY(paths, i); 
     646                         
     647                        wr_send_command(WI_STR("COMMENT %#@%c%#@"), 
     648                                path,           WR_FIELD_SEPARATOR, 
     649                                comment); 
     650                } 
    643651        } 
    644652} 
     
    671679 
    672680static void wr_cmd_get(wi_array_t *arguments) { 
     681        wi_array_t              *paths; 
    673682        uint32_t                i, count; 
    674683         
    675         count = wi_array_count(arguments); 
     684        paths = wr_files_full_paths(arguments); 
     685        count = wi_array_count(paths); 
    676686         
    677687        for(i = 0; i < count; i++) 
    678                 wr_transfer_download(wr_files_full_path(WI_ARRAY(arguments, i))); 
     688                wr_transfer_download(WI_ARRAY(paths, i)); 
    679689         
    680690        wr_draw_transfers(true); 
     
    935945 
    936946static void wr_cmd_mkdir(wi_array_t *arguments) { 
     947        wi_array_t              *paths; 
    937948        uint32_t                i, count; 
    938949         
    939         count = wi_array_count(arguments); 
    940          
     950        paths = wr_files_full_paths(arguments); 
     951        count = wi_array_count(paths); 
     952 
    941953        for(i = 0; i < count; i++) 
    942                 wr_send_command(WI_STR("FOLDER %#@"), wr_files_full_path(WI_ARRAY(arguments, i))); 
     954                wr_send_command(WI_STR("FOLDER %#@"), WI_ARRAY(paths, i)); 
    943955} 
    944956 
     
    9891001 
    9901002static void wr_cmd_mv(wi_array_t *arguments) { 
     1003        wi_array_t              *paths; 
    9911004        wi_string_t             *frompath, *topath; 
     1005        wi_boolean_t    directory; 
    9921006        uint32_t                i, count; 
    9931007         
    994         count = wi_array_count(arguments); 
    995          
    996         if(count == 2) { 
    997                 frompath        = wr_files_full_path(WI_ARRAY(arguments, 0)); 
    998                 topath          = wr_files_full_path(WI_ARRAY(arguments, 1)); 
    999  
    1000                 wr_send_command(WI_STR("MOVE %#@%c%#@"), 
    1001                         frompath,               WR_FIELD_SEPARATOR, 
    1002                         topath); 
     1008        if(wi_array_count(arguments) == 2) { 
     1009                frompath        = WI_ARRAY(arguments, 0); 
     1010                topath          = WI_ARRAY(arguments, 1); 
     1011                directory       = (wi_string_has_suffix(topath, WI_STR("/")) || 
     1012                                           wi_is_equal(topath, WI_STR(".")) || 
     1013                                           wi_is_equal(topath, WI_STR(".."))); 
     1014                frompath        = wr_files_full_path(frompath); 
     1015                topath          = wr_files_full_path(topath); 
     1016                 
     1017                if(directory) { 
     1018                        wr_send_command(WI_STR("MOVE %#@%c%#@/%#@"), 
     1019                                frompath,               WR_FIELD_SEPARATOR, 
     1020                                topath, wi_string_last_path_component(frompath)); 
     1021                } else { 
     1022                        wr_send_command(WI_STR("MOVE %#@%c%#@"), 
     1023                                frompath,               WR_FIELD_SEPARATOR, 
     1024                                topath); 
     1025                } 
    10031026        } else { 
    1004                 topath = wr_files_full_path(wi_array_last_data(arguments)); 
     1027                paths   = wr_files_full_paths(arguments); 
     1028                count   = wi_array_count(paths); 
     1029                topath  = wi_array_last_data(paths); 
    10051030                 
    10061031                for(i = 0; i < count - 1; i++) { 
    1007                         frompath = wr_files_full_path(WI_ARRAY(arguments, i)); 
     1032                        frompath = WI_ARRAY(paths, i); 
    10081033 
    10091034                        wr_send_command(WI_STR("MOVE %#@%c%#@/%#@"), 
     
    12361261 
    12371262static void wr_cmd_rm(wi_array_t *arguments) { 
     1263        wi_array_t              *paths; 
    12381264        uint32_t                i, count; 
    12391265         
    1240         count = wi_array_count(arguments); 
     1266        paths = wr_files_full_paths(arguments); 
     1267        count = wi_array_count(paths); 
    12411268         
    12421269        for(i = 0; i < count; i++) 
    1243                 wr_send_command(WI_STR("DELETE %#@"), wr_files_full_path(WI_ARRAY(arguments, i))); 
     1270                wr_send_command(WI_STR("DELETE %#@"), WI_ARRAY(paths, i)); 
    12441271} 
    12451272 
     
    13781405 
    13791406static void wr_cmd_stat(wi_array_t *arguments) { 
     1407        wi_array_t              *paths; 
    13801408        uint32_t                i, count; 
    13811409         
    13821410        wr_stat_state = WR_STAT_FILE; 
    13831411 
    1384         count = wi_array_count(arguments); 
     1412        paths = wr_files_full_paths(arguments); 
     1413        count = wi_array_count(paths); 
    13851414         
    13861415        for(i = 0; i < count; i++) 
    1387                 wr_send_command(WI_STR("STAT %#@"), wr_files_full_path(WI_ARRAY(arguments, i))); 
     1416                wr_send_command(WI_STR("STAT %#@"), WI_ARRAY(paths, i)); 
    13881417} 
    13891418 
     
    14871516 
    14881517static void wr_cmd_type(wi_array_t *arguments) { 
     1518        wi_array_t                      *paths; 
    14891519        wi_string_t                     *path, *string; 
    14901520        wr_file_type_t          type; 
     
    15051535        } 
    15061536         
    1507         count = wi_array_count(arguments); 
    1508          
    1509         for(i = 0; i < count - 1; i++) { 
    1510                 path = wr_files_full_path(WI_ARRAY(arguments, i)); 
     1537        paths = wr_files_full_paths(wi_array_subarray_with_range(arguments, wi_make_range(0, wi_array_count(arguments) - 1))); 
     1538        count = wi_array_count(paths); 
     1539         
     1540        for(i = 0; i < count; i++) { 
     1541                path = WI_ARRAY(paths, i); 
    15111542                 
    15121543                wr_send_command(WI_STR("TYPE %#@%c%u"), 
  • wire/trunk/wire/files.c

    r3891 r4377  
    146146 
    147147 
     148wi_array_t * wr_files_full_paths(wi_array_t *paths) { 
     149        wi_array_t              *fullpaths; 
     150        uint32_t                i, count; 
     151         
     152        count = wi_array_count(paths); 
     153        fullpaths = wi_array_init_with_capacity(wi_array_alloc(), count); 
     154         
     155        for(i = 0; i < count; i++) 
     156                wi_array_add_data(fullpaths, wr_files_full_path(WI_ARRAY(paths, i))); 
     157         
     158        return wi_autorelease(fullpaths); 
     159} 
     160 
     161 
     162 
    148163wi_string_t * wr_files_string_for_size(wi_file_offset_t size) { 
    149164        double      kb, mb, gb, tb, pb; 
  • wire/trunk/wire/files.h

    r3566 r4377  
    7474 
    7575wi_string_t *                                           wr_files_full_path(wi_string_t *); 
     76wi_array_t *                                            wr_files_full_paths(wi_array_t *); 
    7677wi_string_t *                                           wr_files_string_for_size(wi_file_offset_t); 
    7778wi_string_t *                                           wr_files_string_for_count(unsigned int);