Fossil with Commonmark

Check-in [0a34967beb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the "mv" command so that it will move directories. Patch from Dingyuan Wang.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0a34967beb57cfa1f86d8e16579307743e8a3be2dd3eadbac56b543fa310c440
User & Date: drh 2018-05-29 14:23:47
Context
2018-05-30
01:28
Update the build-in SQLite to the first 3.24.0 beta. check-in: bbdfec3f31 user: drh tags: trunk
2018-05-29
14:23
Fix the "mv" command so that it will move directories. Patch from Dingyuan Wang. check-in: 0a34967beb user: drh tags: trunk
2018-05-21
01:01
Fix harmless compiler warning. check-in: a7056e6499 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/add.c.

   857    857   void mv_cmd(void){
   858    858     int i;
   859    859     int vid;
   860    860     int moveFiles;
   861    861     int dryRunFlag;
   862    862     int softFlag;
   863    863     int hardFlag;
          864  +  int origType;
          865  +  int destType;
   864    866     char *zDest;
   865    867     Blob dest;
   866    868     Stmt q;
   867    869   
   868    870     db_must_be_within_tree();
   869    871     dryRunFlag = find_option("dry-run","n",0)!=0;
   870    872     softFlag = find_option("soft",0,0)!=0;
................................................................................
   898    900     file_tree_name(zDest, &dest, 0, 1);
   899    901     db_multi_exec(
   900    902       "UPDATE vfile SET origname=pathname WHERE origname IS NULL;"
   901    903     );
   902    904     db_multi_exec(
   903    905       "CREATE TEMP TABLE mv(f TEXT UNIQUE ON CONFLICT IGNORE, t TEXT);"
   904    906     );
   905         -  if( file_isdir(zDest, RepoFILE)!=1 ){
          907  +  if( g.argc!=4 ){
          908  +    origType = -1;
          909  +  }else{
          910  +    origType = (file_isdir(g.argv[2], RepoFILE) == 1);
          911  +  }
          912  +  destType = file_isdir(zDest, RepoFILE);
          913  +  if( origType==-1 && destType!=1 ){
          914  +    usage("OLDNAME NEWNAME");
          915  +  }else if( origType==1 && destType==2 ){
          916  +    fossil_fatal("cannot rename '%s' to '%s' since another file named"
          917  +                 " '%s' exists", g.argv[2], zDest, zDest);
          918  +  }else if( origType==0 && destType!=1 ){
   906    919       Blob orig;
   907         -    if( g.argc!=4 ){
   908         -      usage("OLDNAME NEWNAME");
   909         -    }
   910    920       file_tree_name(g.argv[2], &orig, 0, 1);
   911    921       db_multi_exec(
   912    922         "INSERT INTO mv VALUES(%B,%B)", &orig, &dest
   913    923       );
   914    924     }else{
   915    925       if( blob_eq(&dest, ".") ){
   916    926         blob_reset(&dest);
................................................................................
   934    944         );
   935    945         while( db_step(&q)==SQLITE_ROW ){
   936    946           const char *zPath = db_column_text(&q, 0);
   937    947           int nPath = db_column_bytes(&q, 0);
   938    948           const char *zTail;
   939    949           if( nPath==nOrig ){
   940    950             zTail = file_tail(zPath);
          951  +        }else if( destType==1 ){
          952  +          zTail = &zPath[nOrig-strlen(file_tail(zOrig))];
   941    953           }else{
   942    954             zTail = &zPath[nOrig+1];
   943    955           }
   944    956           db_multi_exec(
   945    957             "INSERT INTO mv VALUES('%q','%q%q')",
   946    958             zPath, blob_str(&dest), zTail
   947    959           );