Hex Artifact Content
Not logged in

Artifact c094792c50f04881b59aa5fa6bbe9c164a4b1f0e:

File src/add.c part of check-in [7a2c37063a] - merge trunk into creole branch by bob on 2009-09-22 07:49:39. Also file src/add.c part of check-in [5bc5e88c86] - Add the --dotfiles option to the "add" command to cause fossil to include files whose name begins with "." which recursively adding files. Ticket 2e924cf9b74e. by drh on 2009-08-14 16:19:53.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65  .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75   contains code u
0380: 73 65 64 20 74 6f 20 63 68 65 63 6b 2d 6f 75 74  sed to check-out
0390: 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 74 68 65   versions of the
03a0: 20 70 72 6f 6a 65 63 74 0a 2a 2a 20 66 72 6f 6d   project.** from
03b0: 20 74 68 65 20 6c 6f 63 61 6c 20 72 65 70 6f 73   the local repos
03c0: 69 74 6f 72 79 2e 0a 2a 2f 0a 23 69 6e 63 6c 75  itory..*/.#inclu
03d0: 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 69  de "config.h".#i
03e0: 6e 63 6c 75 64 65 20 22 61 64 64 2e 68 22 0a 23  nclude "add.h".#
03f0: 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e  include <assert.
0400: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 64 69 72  h>.#include <dir
0410: 65 6e 74 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 53 65  ent.h>../*.** Se
0420: 74 20 74 6f 20 74 72 75 65 20 69 66 20 66 69 6c  t to true if fil
0430: 65 73 20 77 68 6f 73 65 20 6e 61 6d 65 73 20 62  es whose names b
0440: 65 67 69 6e 20 77 69 74 68 20 22 2e 22 20 73 68  egin with "." sh
0450: 6f 75 6c 64 20 62 65 0a 2a 2a 20 69 6e 63 6c 75  ould be.** inclu
0460: 64 65 64 20 77 68 65 6e 20 70 72 6f 63 65 73 73  ded when process
0470: 69 6e 67 20 61 20 72 65 63 75 72 73 69 76 65 20  ing a recursive 
0480: 22 61 64 64 22 20 63 6f 6d 6d 61 6e 64 2e 0a 2a  "add" command..*
0490: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 69 6e 63  /.static int inc
04a0: 6c 75 64 65 44 6f 74 46 69 6c 65 73 20 3d 20 30  ludeDotFiles = 0
04b0: 3b 0a 20 20 20 20 0a 2f 2a 0a 2a 2a 20 41 64 64  ;.    ./*.** Add
04c0: 20 61 20 73 69 6e 67 6c 65 20 66 69 6c 65 0a 2a   a single file.*
04d0: 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 61 64  /.static void ad
04e0: 64 5f 6f 6e 65 5f 66 69 6c 65 28 63 6f 6e 73 74  d_one_file(const
04f0: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 69 6e   char *zName, in
0500: 74 20 76 69 64 2c 20 42 6c 6f 62 20 2a 70 4f 6d  t vid, Blob *pOm
0510: 69 74 29 7b 0a 20 20 42 6c 6f 62 20 70 61 74 68  it){.  Blob path
0520: 6e 61 6d 65 3b 0a 20 20 63 6f 6e 73 74 20 63 68  name;.  const ch
0530: 61 72 20 2a 7a 50 61 74 68 3b 0a 20 20 20 20 20  ar *zPath;.     
0540: 20 0a 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61   .  file_tree_na
0550: 6d 65 28 7a 4e 61 6d 65 2c 20 26 70 61 74 68 6e  me(zName, &pathn
0560: 61 6d 65 2c 20 31 29 3b 0a 20 20 7a 50 61 74 68  ame, 1);.  zPath
0570: 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26 70 61 74   = blob_str(&pat
0580: 68 6e 61 6d 65 29 3b 0a 20 20 69 66 28 20 73 74  hname);.  if( st
0590: 72 63 6d 70 28 7a 50 61 74 68 2c 20 22 6d 61 6e  rcmp(zPath, "man
05a0: 69 66 65 73 74 22 29 3d 3d 30 0a 20 20 20 7c 7c  ifest")==0.   ||
05b0: 20 73 74 72 63 6d 70 28 7a 50 61 74 68 2c 20 22   strcmp(zPath, "
05c0: 5f 46 4f 53 53 49 4c 5f 22 29 3d 3d 30 0a 20 20  _FOSSIL_")==0.  
05d0: 20 7c 7c 20 73 74 72 63 6d 70 28 7a 50 61 74 68   || strcmp(zPath
05e0: 2c 20 22 6d 61 6e 69 66 65 73 74 2e 75 75 69 64  , "manifest.uuid
05f0: 22 29 3d 3d 30 0a 20 20 20 7c 7c 20 62 6c 6f 62  ")==0.   || blob
0600: 5f 63 6f 6d 70 61 72 65 28 26 70 61 74 68 6e 61  _compare(&pathna
0610: 6d 65 2c 20 70 4f 6d 69 74 29 3d 3d 30 0a 20 20  me, pOmit)==0.  
0620: 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 77 61  ){.    fossil_wa
0630: 72 6e 69 6e 67 28 22 63 61 6e 6e 6f 74 20 61 64  rning("cannot ad
0640: 64 20 25 73 22 2c 20 7a 50 61 74 68 29 3b 0a 20  d %s", zPath);. 
0650: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 69 66 28 20   }else{.    if( 
0660: 21 66 69 6c 65 5f 69 73 5f 73 69 6d 70 6c 65 5f  !file_is_simple_
0670: 70 61 74 68 6e 61 6d 65 28 7a 50 61 74 68 29 20  pathname(zPath) 
0680: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
0690: 66 61 74 61 6c 28 22 66 69 6c 65 6e 61 6d 65 20  fatal("filename 
06a0: 63 6f 6e 74 61 69 6e 73 20 69 6c 6c 65 67 61 6c  contains illegal
06b0: 20 63 68 61 72 61 63 74 65 72 73 3a 20 25 73 22   characters: %s"
06c0: 2c 20 7a 50 61 74 68 29 3b 0a 20 20 20 20 7d 0a  , zPath);.    }.
06d0: 20 20 20 20 69 66 28 20 64 62 5f 65 78 69 73 74      if( db_exist
06e0: 73 28 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d  s("SELECT 1 FROM
06f0: 20 76 66 69 6c 65 20 57 48 45 52 45 20 70 61 74   vfile WHERE pat
0700: 68 6e 61 6d 65 3d 25 51 22 2c 20 7a 50 61 74 68  hname=%Q", zPath
0710: 29 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75  ) ){.      db_mu
0720: 6c 74 69 5f 65 78 65 63 28 22 55 50 44 41 54 45  lti_exec("UPDATE
0730: 20 76 66 69 6c 65 20 53 45 54 20 64 65 6c 65 74   vfile SET delet
0740: 65 64 3d 30 20 57 48 45 52 45 20 70 61 74 68 6e  ed=0 WHERE pathn
0750: 61 6d 65 3d 25 51 22 2c 20 7a 50 61 74 68 29 3b  ame=%Q", zPath);
0760: 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20  .    }else{.    
0770: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28    db_multi_exec(
0780: 0a 20 20 20 20 20 20 20 20 22 49 4e 53 45 52 54  .        "INSERT
0790: 20 49 4e 54 4f 20 76 66 69 6c 65 28 76 69 64 2c   INTO vfile(vid,
07a0: 64 65 6c 65 74 65 64 2c 72 69 64 2c 6d 72 69 64  deleted,rid,mrid
07b0: 2c 70 61 74 68 6e 61 6d 65 29 22 0a 20 20 20 20  ,pathname)".    
07c0: 20 20 20 20 22 56 41 4c 55 45 53 28 25 64 2c 30      "VALUES(%d,0
07d0: 2c 30 2c 30 2c 25 51 29 22 2c 20 76 69 64 2c 20  ,0,0,%Q)", vid, 
07e0: 7a 50 61 74 68 29 3b 0a 20 20 20 20 7d 0a 20 20  zPath);.    }.  
07f0: 20 20 70 72 69 6e 74 66 28 22 41 44 44 45 44 20    printf("ADDED 
0800: 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 29 3b 0a   %s\n", zPath);.
0810: 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74    }.  blob_reset
0820: 28 26 70 61 74 68 6e 61 6d 65 29 3b 0a 7d 0a 0a  (&pathname);.}..
0830: 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 6f 6e 74 65 6e  /*.** All conten
0840: 74 20 6f 66 20 74 68 65 20 7a 44 69 72 20 64 69  t of the zDir di
0850: 72 65 63 74 6f 72 79 20 74 6f 20 74 68 65 20 53  rectory to the S
0860: 46 49 4c 45 20 74 61 62 6c 65 2e 0a 2a 2f 0a 76  FILE table..*/.v
0870: 6f 69 64 20 61 64 64 5f 64 69 72 65 63 74 6f 72  oid add_director
0880: 79 5f 63 6f 6e 74 65 6e 74 28 63 6f 6e 73 74 20  y_content(const 
0890: 63 68 61 72 20 2a 7a 44 69 72 29 7b 0a 20 20 44  char *zDir){.  D
08a0: 49 52 20 2a 64 3b 0a 20 20 69 6e 74 20 6f 72 69  IR *d;.  int ori
08b0: 67 53 69 7a 65 3b 0a 20 20 73 74 72 75 63 74 20  gSize;.  struct 
08c0: 64 69 72 65 6e 74 20 2a 70 45 6e 74 72 79 3b 0a  dirent *pEntry;.
08d0: 20 20 42 6c 6f 62 20 70 61 74 68 3b 0a 0a 20 20    Blob path;..  
08e0: 62 6c 6f 62 5f 7a 65 72 6f 28 26 70 61 74 68 29  blob_zero(&path)
08f0: 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28  ;.  blob_append(
0900: 26 70 61 74 68 2c 20 7a 44 69 72 2c 20 2d 31 29  &path, zDir, -1)
0910: 3b 0a 20 20 6f 72 69 67 53 69 7a 65 20 3d 20 62  ;.  origSize = b
0920: 6c 6f 62 5f 73 69 7a 65 28 26 70 61 74 68 29 3b  lob_size(&path);
0930: 0a 20 20 64 20 3d 20 6f 70 65 6e 64 69 72 28 7a  .  d = opendir(z
0940: 44 69 72 29 3b 0a 20 20 69 66 28 20 64 20 29 7b  Dir);.  if( d ){
0950: 0a 20 20 20 20 77 68 69 6c 65 28 20 28 70 45 6e  .    while( (pEn
0960: 74 72 79 3d 72 65 61 64 64 69 72 28 64 29 29 21  try=readdir(d))!
0970: 3d 30 20 29 7b 0a 20 20 20 20 20 20 63 68 61 72  =0 ){.      char
0980: 20 2a 7a 50 61 74 68 3b 0a 20 20 20 20 20 20 69   *zPath;.      i
0990: 66 28 20 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d  f( pEntry->d_nam
09a0: 65 5b 30 5d 3d 3d 27 2e 27 20 29 7b 0a 20 20 20  e[0]=='.' ){.   
09b0: 20 20 20 20 20 69 66 28 20 21 69 6e 63 6c 75 64       if( !includ
09c0: 65 44 6f 74 46 69 6c 65 73 20 29 20 63 6f 6e 74  eDotFiles ) cont
09d0: 69 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 69 66  inue;.        if
09e0: 28 20 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d 65  ( pEntry->d_name
09f0: 5b 31 5d 3d 3d 30 20 29 20 63 6f 6e 74 69 6e 75  [1]==0 ) continu
0a00: 65 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 70  e;.        if( p
0a10: 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d 65 5b 31 5d  Entry->d_name[1]
0a20: 3d 3d 27 2e 27 20 26 26 20 70 45 6e 74 72 79 2d  =='.' && pEntry-
0a30: 3e 64 5f 6e 61 6d 65 5b 32 5d 3d 3d 30 20 29 20  >d_name[2]==0 ) 
0a40: 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20  continue;.      
0a50: 7d 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70  }.      blob_app
0a60: 65 6e 64 66 28 26 70 61 74 68 2c 20 22 2f 25 73  endf(&path, "/%s
0a70: 22 2c 20 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d  ", pEntry->d_nam
0a80: 65 29 3b 0a 20 20 20 20 20 20 7a 50 61 74 68 20  e);.      zPath 
0a90: 3d 20 62 6c 6f 62 5f 73 74 72 28 26 70 61 74 68  = blob_str(&path
0aa0: 29 3b 0a 20 20 20 20 20 20 69 66 28 20 66 69 6c  );.      if( fil
0ab0: 65 5f 69 73 64 69 72 28 7a 50 61 74 68 29 3d 3d  e_isdir(zPath)==
0ac0: 31 20 29 7b 0a 20 20 20 20 20 20 20 20 61 64 64  1 ){.        add
0ad0: 5f 64 69 72 65 63 74 6f 72 79 5f 63 6f 6e 74 65  _directory_conte
0ae0: 6e 74 28 7a 50 61 74 68 29 3b 0a 20 20 20 20 20  nt(zPath);.     
0af0: 20 7d 65 6c 73 65 20 69 66 28 20 66 69 6c 65 5f   }else if( file_
0b00: 69 73 66 69 6c 65 28 7a 50 61 74 68 29 20 29 7b  isfile(zPath) ){
0b10: 0a 20 20 20 20 20 20 20 20 64 62 5f 6d 75 6c 74  .        db_mult
0b20: 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 49  i_exec("INSERT I
0b30: 4e 54 4f 20 73 66 69 6c 65 20 56 41 4c 55 45 53  NTO sfile VALUES
0b40: 28 25 51 29 22 2c 20 7a 50 61 74 68 29 3b 0a 20  (%Q)", zPath);. 
0b50: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 6c 6f       }.      blo
0b60: 62 5f 72 65 73 69 7a 65 28 26 70 61 74 68 2c 20  b_resize(&path, 
0b70: 6f 72 69 67 53 69 7a 65 29 3b 0a 20 20 20 20 7d  origSize);.    }
0b80: 0a 20 20 7d 0a 20 20 63 6c 6f 73 65 64 69 72 28  .  }.  closedir(
0b90: 64 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74  d);.  blob_reset
0ba0: 28 26 70 61 74 68 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  (&path);.}../*.*
0bb0: 2a 20 41 64 64 20 61 6c 6c 20 63 6f 6e 74 65 6e  * Add all conten
0bc0: 74 20 6f 66 20 61 20 64 69 72 65 63 74 6f 72 79  t of a directory
0bd0: 2e 0a 2a 2f 0a 76 6f 69 64 20 61 64 64 5f 64 69  ..*/.void add_di
0be0: 72 65 63 74 6f 72 79 28 63 6f 6e 73 74 20 63 68  rectory(const ch
0bf0: 61 72 20 2a 7a 44 69 72 2c 20 69 6e 74 20 76 69  ar *zDir, int vi
0c00: 64 2c 20 42 6c 6f 62 20 2a 70 4f 6d 69 74 29 7b  d, Blob *pOmit){
0c10: 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 61 64 64  .  Stmt q;.  add
0c20: 5f 64 69 72 65 63 74 6f 72 79 5f 63 6f 6e 74 65  _directory_conte
0c30: 6e 74 28 7a 44 69 72 29 3b 0a 20 20 64 62 5f 70  nt(zDir);.  db_p
0c40: 72 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45  repare(&q, "SELE
0c50: 43 54 20 78 20 46 52 4f 4d 20 73 66 69 6c 65 20  CT x FROM sfile 
0c60: 4f 52 44 45 52 20 42 59 20 78 22 29 3b 0a 20 20  ORDER BY x");.  
0c70: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26  while( db_step(&
0c80: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29  q)==SQLITE_ROW )
0c90: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72  {.    const char
0ca0: 20 2a 7a 4e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c   *zName = db_col
0cb0: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 3b  umn_text(&q, 0);
0cc0: 0a 20 20 20 20 61 64 64 5f 6f 6e 65 5f 66 69 6c  .    add_one_fil
0cd0: 65 28 7a 4e 61 6d 65 2c 20 76 69 64 2c 20 70 4f  e(zName, vid, pO
0ce0: 6d 69 74 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66  mit);.  }.  db_f
0cf0: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 64  inalize(&q);.  d
0d00: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45  b_multi_exec("DE
0d10: 4c 45 54 45 20 46 52 4f 4d 20 73 66 69 6c 65 22  LETE FROM sfile"
0d20: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d  );.}../*.** COMM
0d30: 41 4e 44 3a 20 61 64 64 0a 2a 2a 0a 2a 2a 20 55  AND: add.**.** U
0d40: 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 61 64  sage: %fossil ad
0d50: 64 20 46 49 4c 45 2e 2e 2e 0a 2a 2a 0a 2a 2a 20  d FILE....**.** 
0d60: 4d 61 6b 65 20 61 72 72 61 6e 67 65 6d 65 6e 74  Make arrangement
0d70: 73 20 74 6f 20 61 64 64 20 6f 6e 65 20 6f 72 20  s to add one or 
0d80: 6d 6f 72 65 20 66 69 6c 65 73 20 74 6f 20 74 68  more files to th
0d90: 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f  e current checko
0da0: 75 74 20 0a 2a 2a 20 61 74 20 74 68 65 20 6e 65  ut .** at the ne
0db0: 78 74 20 63 6f 6d 6d 69 74 2e 0a 2a 2a 0a 2a 2a  xt commit..**.**
0dc0: 20 57 68 65 6e 20 61 64 64 69 6e 67 20 66 69 6c   When adding fil
0dd0: 65 73 20 72 65 63 75 72 73 69 76 65 6c 79 2c 20  es recursively, 
0de0: 66 69 6c 65 6e 61 6d 65 73 20 74 68 61 74 20 62  filenames that b
0df0: 65 67 69 6e 20 77 69 74 68 20 22 2e 22 20 61 72  egin with "." ar
0e00: 65 0a 2a 2a 20 65 78 63 6c 75 64 65 64 20 62 79  e.** excluded by
0e10: 20 64 65 66 61 75 6c 74 2e 20 20 54 6f 20 69 6e   default.  To in
0e20: 63 6c 75 64 65 20 73 75 63 68 20 66 69 6c 65 73  clude such files
0e30: 2c 20 61 64 64 20 74 68 65 20 22 2d 2d 64 6f 74  , add the "--dot
0e40: 66 69 6c 65 73 22 0a 2a 2a 20 6f 70 74 69 6f 6e  files".** option
0e50: 20 74 6f 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d   to the command-
0e60: 6c 69 6e 65 2e 0a 2a 2f 0a 76 6f 69 64 20 61 64  line..*/.void ad
0e70: 64 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69  d_cmd(void){.  i
0e80: 6e 74 20 69 3b 0a 20 20 69 6e 74 20 76 69 64 3b  nt i;.  int vid;
0e90: 0a 20 20 42 6c 6f 62 20 72 65 70 6f 3b 0a 0a 20  .  Blob repo;.. 
0ea0: 20 69 6e 63 6c 75 64 65 44 6f 74 46 69 6c 65 73   includeDotFiles
0eb0: 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22   = find_option("
0ec0: 64 6f 74 66 69 6c 65 73 22 2c 30 2c 30 29 21 3d  dotfiles",0,0)!=
0ed0: 30 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f  0;.  db_must_be_
0ee0: 77 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20  within_tree();. 
0ef0: 20 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69   vid = db_lget_i
0f00: 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 30 29  nt("checkout",0)
0f10: 3b 0a 20 20 69 66 28 20 76 69 64 3d 3d 30 20 29  ;.  if( vid==0 )
0f20: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e  {.    fossil_pan
0f30: 69 63 28 22 6e 6f 20 63 68 65 63 6b 6f 75 74 20  ic("no checkout 
0f40: 74 6f 20 61 64 64 20 74 6f 22 29 3b 0a 20 20 7d  to add to");.  }
0f50: 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e  .  db_begin_tran
0f60: 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 69 66 28  saction();.  if(
0f70: 20 21 66 69 6c 65 5f 74 72 65 65 5f 6e 61 6d 65   !file_tree_name
0f80: 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61  (g.zRepositoryNa
0f90: 6d 65 2c 20 26 72 65 70 6f 2c 20 30 29 20 29 7b  me, &repo, 0) ){
0fa0: 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26  .    blob_zero(&
0fb0: 72 65 70 6f 29 3b 0a 20 20 7d 0a 20 20 64 62 5f  repo);.  }.  db_
0fc0: 6d 75 6c 74 69 5f 65 78 65 63 28 22 43 52 45 41  multi_exec("CREA
0fd0: 54 45 20 54 45 4d 50 20 54 41 42 4c 45 20 73 66  TE TEMP TABLE sf
0fe0: 69 6c 65 28 78 20 54 45 58 54 20 50 52 49 4d 41  ile(x TEXT PRIMA
0ff0: 52 59 20 4b 45 59 29 22 29 3b 0a 20 20 66 6f 72  RY KEY)");.  for
1000: 28 69 3d 32 3b 20 69 3c 67 2e 61 72 67 63 3b 20  (i=2; i<g.argc; 
1010: 69 2b 2b 29 7b 0a 20 20 20 20 63 68 61 72 20 2a  i++){.    char *
1020: 7a 4e 61 6d 65 3b 0a 20 20 20 20 69 6e 74 20 69  zName;.    int i
1030: 73 44 69 72 3b 0a 0a 20 20 20 20 7a 4e 61 6d 65  sDir;..    zName
1040: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 2f 22 2c   = mprintf("%/",
1050: 20 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 20 20 20   g.argv[i]);.   
1060: 20 69 73 44 69 72 20 3d 20 66 69 6c 65 5f 69 73   isDir = file_is
1070: 64 69 72 28 7a 4e 61 6d 65 29 3b 0a 20 20 20 20  dir(zName);.    
1080: 69 66 28 20 69 73 44 69 72 3d 3d 31 20 29 7b 0a  if( isDir==1 ){.
1090: 20 20 20 20 20 20 61 64 64 5f 64 69 72 65 63 74        add_direct
10a0: 6f 72 79 28 7a 4e 61 6d 65 2c 20 76 69 64 2c 20  ory(zName, vid, 
10b0: 26 72 65 70 6f 29 3b 0a 20 20 20 20 7d 65 6c 73  &repo);.    }els
10c0: 65 20 69 66 28 20 69 73 44 69 72 3d 3d 30 20 29  e if( isDir==0 )
10d0: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66  {.      fossil_f
10e0: 61 74 61 6c 28 22 6e 6f 74 20 66 6f 75 6e 64 3a  atal("not found:
10f0: 20 25 73 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20   %s", zName);.  
1100: 20 20 7d 65 6c 73 65 20 69 66 28 20 61 63 63 65    }else if( acce
1110: 73 73 28 7a 4e 61 6d 65 2c 20 52 5f 4f 4b 29 20  ss(zName, R_OK) 
1120: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
1130: 66 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 6f 70  fatal("cannot op
1140: 65 6e 20 25 73 22 2c 20 7a 4e 61 6d 65 29 3b 0a  en %s", zName);.
1150: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20      }else{.     
1160: 20 61 64 64 5f 6f 6e 65 5f 66 69 6c 65 28 7a 4e   add_one_file(zN
1170: 61 6d 65 2c 20 76 69 64 2c 20 26 72 65 70 6f 29  ame, vid, &repo)
1180: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 72 65 65  ;.    }.    free
1190: 28 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 64  (zName);.  }.  d
11a0: 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f  b_end_transactio
11b0: 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43  n(0);.}../*.** C
11c0: 4f 4d 4d 41 4e 44 3a 20 72 6d 0a 2a 2a 20 43 4f  OMMAND: rm.** CO
11d0: 4d 4d 41 4e 44 3a 20 64 65 6c 0a 2a 2a 0a 2a 2a  MMAND: del.**.**
11e0: 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20   Usage: %fossil 
11f0: 72 6d 20 46 49 4c 45 2e 2e 2e 0a 2a 2a 20 20 20  rm FILE....**   
1200: 20 6f 72 3a 20 25 66 6f 73 73 69 6c 20 64 65 6c   or: %fossil del
1210: 20 46 49 4c 45 2e 2e 2e 0a 2a 2a 0a 2a 2a 20 52   FILE....**.** R
1220: 65 6d 6f 76 65 20 6f 6e 65 20 6f 72 20 6d 6f 72  emove one or mor
1230: 65 20 66 69 6c 65 73 20 66 72 6f 6d 20 74 68 65  e files from the
1240: 20 74 72 65 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 69   tree..**.** Thi
1250: 73 20 63 6f 6d 6d 61 6e 64 20 64 6f 65 73 20 6e  s command does n
1260: 6f 74 20 72 65 6d 6f 76 65 20 74 68 65 20 66 69  ot remove the fi
1270: 6c 65 73 20 66 72 6f 6d 20 64 69 73 6b 2e 20 20  les from disk.  
1280: 49 74 20 6a 75 73 74 20 6d 61 72 6b 73 20 74 68  It just marks th
1290: 65 0a 2a 2a 20 66 69 6c 65 73 20 61 73 20 6e 6f  e.** files as no
12a0: 20 6c 6f 6e 67 65 72 20 62 65 69 6e 67 20 70 61   longer being pa
12b0: 72 74 20 6f 66 20 74 68 65 20 70 72 6f 6a 65 63  rt of the projec
12c0: 74 2e 20 20 49 6e 20 6f 74 68 65 72 20 77 6f 72  t.  In other wor
12d0: 64 73 2c 20 66 75 74 75 72 65 0a 2a 2a 20 63 68  ds, future.** ch
12e0: 61 6e 67 65 73 20 74 6f 20 74 68 65 20 6e 61 6d  anges to the nam
12f0: 65 64 20 66 69 6c 65 73 20 77 69 6c 6c 20 6e 6f  ed files will no
1300: 74 20 62 65 20 76 65 72 73 69 6f 6e 65 64 2e 0a  t be versioned..
1310: 2a 2f 0a 76 6f 69 64 20 64 65 6c 5f 63 6d 64 28  */.void del_cmd(
1320: 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 3b 0a  void){.  int i;.
1330: 20 20 69 6e 74 20 76 69 64 3b 0a 0a 20 20 64 62    int vid;..  db
1340: 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f  _must_be_within_
1350: 74 72 65 65 28 29 3b 0a 20 20 76 69 64 20 3d 20  tree();.  vid = 
1360: 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65  db_lget_int("che
1370: 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20 69 66  ckout", 0);.  if
1380: 28 20 76 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20  ( vid==0 ){.    
1390: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 6e 6f  fossil_panic("no
13a0: 20 63 68 65 63 6b 6f 75 74 20 74 6f 20 72 65 6d   checkout to rem
13b0: 6f 76 65 20 66 72 6f 6d 22 29 3b 0a 20 20 7d 0a  ove from");.  }.
13c0: 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73    db_begin_trans
13d0: 61 63 74 69 6f 6e 28 29 3b 0a 20 20 66 6f 72 28  action();.  for(
13e0: 69 3d 32 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69  i=2; i<g.argc; i
13f0: 2b 2b 29 7b 0a 20 20 20 20 63 68 61 72 20 2a 7a  ++){.    char *z
1400: 4e 61 6d 65 3b 0a 20 20 20 20 63 68 61 72 20 2a  Name;.    char *
1410: 7a 50 61 74 68 3b 0a 20 20 20 20 42 6c 6f 62 20  zPath;.    Blob 
1420: 70 61 74 68 6e 61 6d 65 3b 0a 0a 20 20 20 20 7a  pathname;..    z
1430: 4e 61 6d 65 20 3d 20 6d 70 72 69 6e 74 66 28 22  Name = mprintf("
1440: 25 2f 22 2c 20 67 2e 61 72 67 76 5b 69 5d 29 3b  %/", g.argv[i]);
1450: 0a 20 20 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e  .    file_tree_n
1460: 61 6d 65 28 7a 4e 61 6d 65 2c 20 26 70 61 74 68  ame(zName, &path
1470: 6e 61 6d 65 2c 20 31 29 3b 0a 20 20 20 20 7a 50  name, 1);.    zP
1480: 61 74 68 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26  ath = blob_str(&
1490: 70 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 69  pathname);.    i
14a0: 66 28 20 21 64 62 5f 65 78 69 73 74 73 28 0a 20  f( !db_exists(. 
14b0: 20 20 20 20 20 20 20 20 20 20 20 20 22 53 45 4c              "SEL
14c0: 45 43 54 20 31 20 46 52 4f 4d 20 76 66 69 6c 65  ECT 1 FROM vfile
14d0: 20 57 48 45 52 45 20 70 61 74 68 6e 61 6d 65 3d   WHERE pathname=
14e0: 25 51 20 41 4e 44 20 4e 4f 54 20 64 65 6c 65 74  %Q AND NOT delet
14f0: 65 64 22 2c 20 7a 50 61 74 68 29 20 29 7b 0a 20  ed", zPath) ){. 
1500: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61       fossil_fata
1510: 6c 28 22 6e 6f 74 20 69 6e 20 74 68 65 20 72 65  l("not in the re
1520: 70 6f 73 69 74 6f 72 79 3a 20 25 73 22 2c 20 7a  pository: %s", z
1530: 4e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65  Name);.    }else
1540: 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69  {.      db_multi
1550: 5f 65 78 65 63 28 22 55 50 44 41 54 45 20 76 66  _exec("UPDATE vf
1560: 69 6c 65 20 53 45 54 20 64 65 6c 65 74 65 64 3d  ile SET deleted=
1570: 31 20 57 48 45 52 45 20 70 61 74 68 6e 61 6d 65  1 WHERE pathname
1580: 3d 25 51 22 2c 20 7a 50 61 74 68 29 3b 0a 20 20  =%Q", zPath);.  
1590: 20 20 7d 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73    }.    blob_res
15a0: 65 74 28 26 70 61 74 68 6e 61 6d 65 29 3b 0a 20  et(&pathname);. 
15b0: 20 20 20 66 72 65 65 28 7a 4e 61 6d 65 29 3b 0a     free(zName);.
15c0: 20 20 7d 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65    }.  db_multi_e
15d0: 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d  xec("DELETE FROM
15e0: 20 76 66 69 6c 65 20 57 48 45 52 45 20 64 65 6c   vfile WHERE del
15f0: 65 74 65 64 20 41 4e 44 20 72 69 64 3d 30 22 29  eted AND rid=0")
1600: 3b 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73  ;.  db_end_trans
1610: 61 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a  action(0);.}../*
1620: 0a 2a 2a 20 52 65 6e 61 6d 65 20 61 20 73 69 6e  .** Rename a sin
1630: 67 6c 65 20 66 69 6c 65 2e 20 20 0a 2a 2a 0a 2a  gle file.  .**.*
1640: 2a 20 54 68 65 20 6f 72 69 67 69 6e 61 6c 20 6e  * The original n
1650: 61 6d 65 20 6f 66 20 74 68 65 20 66 69 6c 65 20  ame of the file 
1660: 69 73 20 7a 4f 72 69 67 2e 20 20 54 68 65 20 6e  is zOrig.  The n
1670: 65 77 20 66 69 6c 65 6e 61 6d 65 20 69 73 20 7a  ew filename is z
1680: 4e 65 77 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76  New..*/.static v
1690: 6f 69 64 20 6d 76 5f 6f 6e 65 5f 66 69 6c 65 28  oid mv_one_file(
16a0: 69 6e 74 20 76 69 64 2c 20 63 6f 6e 73 74 20 63  int vid, const c
16b0: 68 61 72 20 2a 7a 4f 72 69 67 2c 20 63 6f 6e 73  har *zOrig, cons
16c0: 74 20 63 68 61 72 20 2a 7a 4e 65 77 29 7b 0a 20  t char *zNew){. 
16d0: 20 70 72 69 6e 74 66 28 22 52 45 4e 41 4d 45 20   printf("RENAME 
16e0: 25 73 20 25 73 5c 6e 22 2c 20 7a 4f 72 69 67 2c  %s %s\n", zOrig,
16f0: 20 7a 4e 65 77 29 3b 0a 20 20 64 62 5f 6d 75 6c   zNew);.  db_mul
1700: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 22 55 50  ti_exec(.    "UP
1710: 44 41 54 45 20 76 66 69 6c 65 20 53 45 54 20 70  DATE vfile SET p
1720: 61 74 68 6e 61 6d 65 3d 27 25 73 27 20 57 48 45  athname='%s' WHE
1730: 52 45 20 70 61 74 68 6e 61 6d 65 3d 27 25 73 27  RE pathname='%s'
1740: 20 41 4e 44 20 76 69 64 3d 25 64 22 2c 0a 20 20   AND vid=%d",.  
1750: 20 20 7a 4e 65 77 2c 20 7a 4f 72 69 67 2c 20 76    zNew, zOrig, v
1760: 69 64 0a 20 20 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a  id.  );.}../*.**
1770: 20 43 4f 4d 4d 41 4e 44 3a 20 6d 76 0a 2a 2a 20   COMMAND: mv.** 
1780: 43 4f 4d 4d 41 4e 44 3a 20 72 65 6e 61 6d 65 0a  COMMAND: rename.
1790: 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f  **.** Usage: %fo
17a0: 73 73 69 6c 20 6d 76 7c 72 65 6e 61 6d 65 20 4f  ssil mv|rename O
17b0: 4c 44 4e 41 4d 45 20 4e 45 57 4e 41 4d 45 0a 2a  LDNAME NEWNAME.*
17c0: 2a 20 20 20 20 6f 72 3a 20 25 66 6f 73 73 69 6c  *    or: %fossil
17d0: 20 6d 76 7c 72 65 6e 61 6d 65 20 4f 4c 44 4e 41   mv|rename OLDNA
17e0: 4d 45 2e 2e 2e 20 44 49 52 0a 2a 2a 0a 2a 2a 20  ME... DIR.**.** 
17f0: 4d 6f 76 65 20 6f 72 20 72 65 6e 61 6d 65 20 6f  Move or rename o
1800: 6e 65 20 6f 72 20 6d 6f 72 65 20 66 69 6c 65 73  ne or more files
1810: 20 77 69 74 68 69 6e 20 74 68 65 20 74 72 65 65   within the tree
1820: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 63 6f 6d 6d  .**.** This comm
1830: 61 6e 64 20 64 6f 65 73 20 6e 6f 74 20 72 65 6e  and does not ren
1840: 61 6d 65 20 74 68 65 20 66 69 6c 65 73 20 6f 6e  ame the files on
1850: 20 64 69 73 6b 2e 20 20 41 6c 6c 20 74 68 69 73   disk.  All this
1860: 20 63 6f 6d 6d 61 6e 64 20 64 6f 65 73 20 69 73   command does is
1870: 0a 2a 2a 20 72 65 63 6f 72 64 20 74 68 65 20 66  .** record the f
1880: 61 63 74 20 74 68 61 74 20 66 69 6c 65 6e 61 6d  act that filenam
1890: 65 73 20 68 61 76 65 20 63 68 61 6e 67 65 64 20  es have changed 
18a0: 73 6f 20 74 68 61 74 20 61 70 70 72 6f 70 72 69  so that appropri
18b0: 61 74 65 20 6e 6f 74 61 74 69 6f 6e 73 0a 2a 2a  ate notations.**
18c0: 20 63 61 6e 20 62 65 20 6d 61 64 65 20 61 74 20   can be made at 
18d0: 74 68 65 20 6e 65 78 74 20 63 6f 6d 6d 69 74 2f  the next commit/
18e0: 63 68 65 63 6b 69 6e 2e 0a 2a 2f 0a 76 6f 69 64  checkin..*/.void
18f0: 20 6d 76 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20   mv_cmd(void){. 
1900: 20 69 6e 74 20 69 3b 0a 20 20 69 6e 74 20 76 69   int i;.  int vi
1910: 64 3b 0a 20 20 63 68 61 72 20 2a 7a 44 65 73 74  d;.  char *zDest
1920: 3b 0a 20 20 42 6c 6f 62 20 64 65 73 74 3b 0a 20  ;.  Blob dest;. 
1930: 20 53 74 6d 74 20 71 3b 0a 0a 20 20 64 62 5f 6d   Stmt q;..  db_m
1940: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72  ust_be_within_tr
1950: 65 65 28 29 3b 0a 20 20 76 69 64 20 3d 20 64 62  ee();.  vid = db
1960: 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b  _lget_int("check
1970: 6f 75 74 22 2c 20 30 29 3b 0a 20 20 69 66 28 20  out", 0);.  if( 
1980: 76 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f  vid==0 ){.    fo
1990: 73 73 69 6c 5f 70 61 6e 69 63 28 22 6e 6f 20 63  ssil_panic("no c
19a0: 68 65 63 6b 6f 75 74 20 72 65 6e 61 6d 65 20 66  heckout rename f
19b0: 69 6c 65 73 20 69 6e 22 29 3b 0a 20 20 7d 0a 20  iles in");.  }. 
19c0: 20 69 66 28 20 67 2e 61 72 67 63 3c 34 20 29 7b   if( g.argc<4 ){
19d0: 0a 20 20 20 20 75 73 61 67 65 28 22 4f 4c 44 4e  .    usage("OLDN
19e0: 41 4d 45 20 4e 45 57 4e 41 4d 45 22 29 3b 0a 20  AME NEWNAME");. 
19f0: 20 7d 0a 20 20 7a 44 65 73 74 20 3d 20 67 2e 61   }.  zDest = g.a
1a00: 72 67 76 5b 67 2e 61 72 67 63 2d 31 5d 3b 0a 20  rgv[g.argc-1];. 
1a10: 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61   db_begin_transa
1a20: 63 74 69 6f 6e 28 29 3b 0a 20 20 66 69 6c 65 5f  ction();.  file_
1a30: 74 72 65 65 5f 6e 61 6d 65 28 7a 44 65 73 74 2c  tree_name(zDest,
1a40: 20 26 64 65 73 74 2c 20 31 29 3b 0a 20 20 64 62   &dest, 1);.  db
1a50: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20  _multi_exec(.   
1a60: 20 22 55 50 44 41 54 45 20 76 66 69 6c 65 20 53   "UPDATE vfile S
1a70: 45 54 20 6f 72 69 67 6e 61 6d 65 3d 70 61 74 68  ET origname=path
1a80: 6e 61 6d 65 20 57 48 45 52 45 20 6f 72 69 67 6e  name WHERE orign
1a90: 61 6d 65 20 49 53 20 4e 55 4c 4c 3b 22 0a 20 20  ame IS NULL;".  
1aa0: 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78  );.  db_multi_ex
1ab0: 65 63 28 0a 20 20 20 20 22 43 52 45 41 54 45 20  ec(.    "CREATE 
1ac0: 54 45 4d 50 20 54 41 42 4c 45 20 6d 76 28 66 20  TEMP TABLE mv(f 
1ad0: 54 45 58 54 20 55 4e 49 51 55 45 20 4f 4e 20 43  TEXT UNIQUE ON C
1ae0: 4f 4e 46 4c 49 43 54 20 49 47 4e 4f 52 45 2c 20  ONFLICT IGNORE, 
1af0: 74 20 54 45 58 54 29 3b 22 0a 20 20 29 3b 0a 20  t TEXT);".  );. 
1b00: 20 69 66 28 20 66 69 6c 65 5f 69 73 64 69 72 28   if( file_isdir(
1b10: 7a 44 65 73 74 29 21 3d 31 20 29 7b 0a 20 20 20  zDest)!=1 ){.   
1b20: 20 42 6c 6f 62 20 6f 72 69 67 3b 0a 20 20 20 20   Blob orig;.    
1b30: 69 66 28 20 67 2e 61 72 67 63 21 3d 34 20 29 7b  if( g.argc!=4 ){
1b40: 0a 20 20 20 20 20 20 75 73 61 67 65 28 22 4f 4c  .      usage("OL
1b50: 44 4e 41 4d 45 20 4e 45 57 4e 41 4d 45 22 29 3b  DNAME NEWNAME");
1b60: 0a 20 20 20 20 7d 0a 20 20 20 20 66 69 6c 65 5f  .    }.    file_
1b70: 74 72 65 65 5f 6e 61 6d 65 28 67 2e 61 72 67 76  tree_name(g.argv
1b80: 5b 32 5d 2c 20 26 6f 72 69 67 2c 20 31 29 3b 0a  [2], &orig, 1);.
1b90: 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65      db_multi_exe
1ba0: 63 28 0a 20 20 20 20 20 20 22 49 4e 53 45 52 54  c(.      "INSERT
1bb0: 20 49 4e 54 4f 20 6d 76 20 56 41 4c 55 45 53 28   INTO mv VALUES(
1bc0: 25 42 2c 25 42 29 22 2c 20 26 6f 72 69 67 2c 20  %B,%B)", &orig, 
1bd0: 26 64 65 73 74 0a 20 20 20 20 29 3b 0a 20 20 7d  &dest.    );.  }
1be0: 65 6c 73 65 7b 0a 20 20 20 20 69 66 28 20 62 6c  else{.    if( bl
1bf0: 6f 62 5f 65 71 28 26 64 65 73 74 2c 20 22 2e 22  ob_eq(&dest, "."
1c00: 29 20 29 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f  ) ){.      blob_
1c10: 72 65 73 65 74 28 26 64 65 73 74 29 3b 0a 20 20  reset(&dest);.  
1c20: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 62    }else{.      b
1c30: 6c 6f 62 5f 61 70 70 65 6e 64 28 26 64 65 73 74  lob_append(&dest
1c40: 2c 20 22 2f 22 2c 20 31 29 3b 0a 20 20 20 20 7d  , "/", 1);.    }
1c50: 0a 20 20 20 20 66 6f 72 28 69 3d 32 3b 20 69 3c  .    for(i=2; i<
1c60: 67 2e 61 72 67 63 2d 31 3b 20 69 2b 2b 29 7b 0a  g.argc-1; i++){.
1c70: 20 20 20 20 20 20 42 6c 6f 62 20 6f 72 69 67 3b        Blob orig;
1c80: 0a 20 20 20 20 20 20 63 68 61 72 20 2a 7a 4f 72  .      char *zOr
1c90: 69 67 3b 0a 20 20 20 20 20 20 69 6e 74 20 6e 4f  ig;.      int nO
1ca0: 72 69 67 3b 0a 20 20 20 20 20 20 66 69 6c 65 5f  rig;.      file_
1cb0: 74 72 65 65 5f 6e 61 6d 65 28 67 2e 61 72 67 76  tree_name(g.argv
1cc0: 5b 69 5d 2c 20 26 6f 72 69 67 2c 20 31 29 3b 0a  [i], &orig, 1);.
1cd0: 20 20 20 20 20 20 7a 4f 72 69 67 20 3d 20 62 6c        zOrig = bl
1ce0: 6f 62 5f 73 74 72 28 26 6f 72 69 67 29 3b 0a 20  ob_str(&orig);. 
1cf0: 20 20 20 20 20 6e 4f 72 69 67 20 3d 20 62 6c 6f       nOrig = blo
1d00: 62 5f 73 69 7a 65 28 26 6f 72 69 67 29 3b 0a 20  b_size(&orig);. 
1d10: 20 20 20 20 20 64 62 5f 70 72 65 70 61 72 65 28       db_prepare(
1d20: 26 71 2c 0a 20 20 20 20 20 20 20 20 20 22 53 45  &q,.         "SE
1d30: 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 20 46 52  LECT pathname FR
1d40: 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 20 20  OM vfile".      
1d50: 20 20 20 22 20 57 48 45 52 45 20 76 69 64 3d 25     " WHERE vid=%
1d60: 64 22 0a 20 20 20 20 20 20 20 20 20 22 20 20 20  d".         "   
1d70: 41 4e 44 20 28 70 61 74 68 6e 61 6d 65 3d 27 25  AND (pathname='%
1d80: 73 27 20 4f 52 20 70 61 74 68 6e 61 6d 65 20 47  s' OR pathname G
1d90: 4c 4f 42 20 27 25 73 2f 2a 27 29 22 0a 20 20 20  LOB '%s/*')".   
1da0: 20 20 20 20 20 20 22 20 4f 52 44 45 52 20 42 59        " ORDER BY
1db0: 20 31 22 2c 0a 20 20 20 20 20 20 20 20 20 76 69   1",.         vi
1dc0: 64 2c 20 7a 4f 72 69 67 2c 20 7a 4f 72 69 67 0a  d, zOrig, zOrig.
1dd0: 20 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20 77        );.      w
1de0: 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71  hile( db_step(&q
1df0: 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b  )==SQLITE_ROW ){
1e00: 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63  .        const c
1e10: 68 61 72 20 2a 7a 50 61 74 68 20 3d 20 64 62 5f  har *zPath = db_
1e20: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20  column_text(&q, 
1e30: 30 29 3b 0a 20 20 20 20 20 20 20 20 69 6e 74 20  0);.        int 
1e40: 6e 50 61 74 68 20 3d 20 64 62 5f 63 6f 6c 75 6d  nPath = db_colum
1e50: 6e 5f 62 79 74 65 73 28 26 71 2c 20 30 29 3b 0a  n_bytes(&q, 0);.
1e60: 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68          const ch
1e70: 61 72 20 2a 7a 54 61 69 6c 3b 0a 20 20 20 20 20  ar *zTail;.     
1e80: 20 20 20 69 66 28 20 6e 50 61 74 68 3d 3d 6e 4f     if( nPath==nO
1e90: 72 69 67 20 29 7b 0a 20 20 20 20 20 20 20 20 20  rig ){.         
1ea0: 20 7a 54 61 69 6c 20 3d 20 66 69 6c 65 5f 74 61   zTail = file_ta
1eb0: 69 6c 28 7a 50 61 74 68 29 3b 0a 20 20 20 20 20  il(zPath);.     
1ec0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
1ed0: 20 20 20 20 7a 54 61 69 6c 20 3d 20 26 7a 50 61      zTail = &zPa
1ee0: 74 68 5b 6e 4f 72 69 67 2b 31 5d 3b 0a 20 20 20  th[nOrig+1];.   
1ef0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 64       }.        d
1f00: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20  b_multi_exec(.  
1f10: 20 20 20 20 20 20 20 20 22 49 4e 53 45 52 54 20          "INSERT 
1f20: 49 4e 54 4f 20 6d 76 20 56 41 4c 55 45 53 28 27  INTO mv VALUES('
1f30: 25 73 27 2c 27 25 73 25 73 27 29 22 2c 0a 20 20  %s','%s%s')",.  
1f40: 20 20 20 20 20 20 20 20 7a 50 61 74 68 2c 20 62          zPath, b
1f50: 6c 6f 62 5f 73 74 72 28 26 64 65 73 74 29 2c 20  lob_str(&dest), 
1f60: 7a 54 61 69 6c 0a 20 20 20 20 20 20 20 20 29 3b  zTail.        );
1f70: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64  .      }.      d
1f80: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a  b_finalize(&q);.
1f90: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 70      }.  }.  db_p
1fa0: 72 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45  repare(&q, "SELE
1fb0: 43 54 20 66 2c 20 74 20 46 52 4f 4d 20 6d 76 20  CT f, t FROM mv 
1fc0: 4f 52 44 45 52 20 42 59 20 66 22 29 3b 0a 20 20  ORDER BY f");.  
1fd0: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26  while( db_step(&
1fe0: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29  q)==SQLITE_ROW )
1ff0: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72  {.    const char
2000: 20 2a 7a 46 72 6f 6d 20 3d 20 64 62 5f 63 6f 6c   *zFrom = db_col
2010: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 3b  umn_text(&q, 0);
2020: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
2030: 2a 7a 54 6f 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e  *zTo = db_column
2040: 5f 74 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 20  _text(&q, 1);.  
2050: 20 20 6d 76 5f 6f 6e 65 5f 66 69 6c 65 28 76 69    mv_one_file(vi
2060: 64 2c 20 7a 46 72 6f 6d 2c 20 7a 54 6f 29 3b 0a  d, zFrom, zTo);.
2070: 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a    }.  db_finaliz
2080: 65 28 26 71 29 3b 0a 20 20 64 62 5f 65 6e 64 5f  e(&q);.  db_end_
2090: 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a  transaction(0);.
20a0: 7d 0a                                            }.