Hex Artifact Content
Not logged in

Artifact 81214718116c3828321fbc5a3db4b54970fa52ae:

File src/construct.c part of check-in [097479f99a] - Better defaults for new databases and clones. Use *CURRENT* to identify the current checkout for TTY timelines. by drh on 2007-09-26 02:00:26.

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 41 6e 64 72 65 61 73  (c) 2007 Andreas
0020: 20 4b 75 70 72 69 65 73 0a 2a 2a 0a 2a 2a 20 54   Kupries.**.** 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 61 6b 75 70 72 69 65 73 40 73 68 61 77 2e 63   akupries@shaw.c
02f0: 61 0a 2a 2a 20 20 20 0a 2a 2a 0a 2a 2a 2a 2a 2a  a.**   .**.*****
0300: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0310: 2a 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 0a 2a 2a 0a 2a 2a  **********.**.**
0350: 20 54 68 69 73 20 66 69 6c 65 20 63 6f 6e 74 61   This file conta
0360: 69 6e 73 20 63 6f 64 65 20 75 73 65 64 20 74 6f  ins code used to
0370: 20 64 65 2d 20 61 6e 64 20 72 65 63 6f 6e 73 74   de- and reconst
0380: 72 75 63 74 20 61 20 72 65 70 6f 73 69 74 6f 72  ruct a repositor
0390: 79 0a 2a 2a 20 69 6e 74 6f 20 61 6e 64 20 66 72  y.** into and fr
03a0: 6f 6d 20 61 6e 20 69 6e 64 69 63 61 74 65 64 20  om an indicated 
03b0: 64 69 72 65 63 74 6f 72 79 2e 0a 2a 2f 0a 23 69  directory..*/.#i
03c0: 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68  nclude "config.h
03d0: 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 73  ".#include "cons
03e0: 74 72 75 63 74 2e 68 22 0a 23 69 6e 63 6c 75 64  truct.h".#includ
03f0: 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 23 69 6e  e <assert.h>.#in
0400: 63 6c 75 64 65 20 3c 73 79 73 2f 74 79 70 65 73  clude <sys/types
0410: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 64 69  .h>.#include <di
0420: 72 65 6e 74 2e 68 3e 0a 0a 2f 2a 20 54 68 69 73  rent.h>../* This
0430: 20 66 75 6e 63 74 69 6f 6e 20 72 65 63 75 72 73   function recurs
0440: 69 76 65 6c 79 20 73 63 61 6e 73 20 74 68 65 20  ively scans the 
0450: 64 69 72 65 63 74 6f 72 79 20 68 69 65 72 61 72  directory hierar
0460: 63 68 79 20 73 74 61 72 74 69 6e 67 20 61 74 0a  chy starting at.
0470: 2a 2a 20 7a 4f 72 69 67 69 6e 20 61 6e 64 20 65  ** zOrigin and e
0480: 6e 74 65 72 73 20 61 6c 6c 20 66 6f 75 6e 64 20  nters all found 
0490: 66 69 6c 65 73 20 69 6e 74 6f 20 74 68 65 20 72  files into the r
04a0: 65 70 6f 73 69 74 6f 72 79 2e 20 54 68 65 20 75  epository. The u
04b0: 75 69 64 20 69 73 0a 2a 2a 20 67 65 6e 65 72 61  uid is.** genera
04c0: 74 65 64 20 66 72 6f 6d 20 74 68 65 20 66 69 6c  ted from the fil
04d0: 65 20 63 6f 6e 74 65 6e 74 73 2c 20 61 6e 64 20  e contents, and 
04e0: 6e 6f 74 20 74 61 6b 65 6e 20 66 72 6f 6d 20 74  not taken from t
04f0: 68 65 2c 20 70 6f 73 73 69 62 6c 79 0a 2a 2a 20  he, possibly.** 
0500: 6d 6f 64 69 66 69 65 64 2c 20 66 69 6c 65 20 6e  modified, file n
0510: 61 6d 65 2e 20 57 68 69 6c 65 20 66 75 6e 63 74  ame. While funct
0520: 69 6f 6e 20 69 73 20 61 62 6c 65 20 74 6f 20 68  ion is able to h
0530: 61 6e 64 6c 65 20 74 68 65 20 64 69 72 65 63 74  andle the direct
0540: 6f 72 79 0a 2a 2a 20 73 74 72 75 63 74 75 72 65  ory.** structure
0550: 20 63 72 65 61 74 65 64 20 62 79 20 27 64 65 63   created by 'dec
0560: 6f 6e 73 74 72 75 63 74 27 20 69 74 20 63 61 6e  onstruct' it can
0570: 20 61 63 74 75 61 6c 6c 79 20 6d 75 63 68 20 6d   actually much m
0580: 6f 72 65 2e 0a 2a 2f 0a 0a 73 74 61 74 69 63 20  ore..*/..static 
0590: 69 6e 74 20 69 6d 70 6f 72 74 5f 6f 72 69 67 69  int import_origi
05a0: 6e 28 63 6f 6e 73 74 20 63 68 61 72 2a 20 7a 4f  n(const char* zO
05b0: 72 69 67 69 6e 29 7b 0a 20 20 44 49 52 20 2a 64  rigin){.  DIR *d
05c0: 3b 0a 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d 20  ;.  int count = 
05d0: 30 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  0;.  const char 
05e0: 2a 7a 46 6f 72 6d 61 74 3b 0a 20 20 63 6f 6e 73  *zFormat;.  cons
05f0: 74 20 63 68 61 72 20 2a 7a 44 69 72 20 3d 20 7a  t char *zDir = z
0600: 4f 72 69 67 69 6e 3b 0a 20 20 73 74 72 75 63 74  Origin;.  struct
0610: 20 64 69 72 65 6e 74 20 2a 70 45 6e 74 72 79 3b   dirent *pEntry;
0620: 0a 0a 20 20 69 66 28 20 7a 44 69 72 5b 30 5d 3d  ..  if( zDir[0]=
0630: 3d 30 20 29 7b 0a 20 20 20 20 20 7a 44 69 72 20  =0 ){.     zDir 
0640: 3d 20 22 2e 22 3b 0a 20 20 20 20 20 7a 46 6f 72  = ".";.     zFor
0650: 6d 61 74 20 3d 20 22 25 73 25 73 22 3b 0a 20 20  mat = "%s%s";.  
0660: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 7a 46 6f 72  }else{.     zFor
0670: 6d 61 74 20 3d 20 22 25 73 2f 25 73 22 3b 0a 20  mat = "%s/%s";. 
0680: 20 7d 0a 0a 20 20 64 20 3d 20 6f 70 65 6e 64 69   }..  d = opendi
0690: 72 28 7a 44 69 72 29 3b 0a 20 20 69 66 28 20 64  r(zDir);.  if( d
06a0: 20 29 7b 0a 20 20 20 20 77 68 69 6c 65 28 20 28   ){.    while( (
06b0: 70 45 6e 74 72 79 3d 72 65 61 64 64 69 72 28 64  pEntry=readdir(d
06c0: 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 20 20 63  ))!=0 ){.      c
06d0: 68 61 72 20 2a 7a 50 61 74 68 3b 0a 20 20 20 20  har *zPath;.    
06e0: 20 20 69 66 28 20 70 45 6e 74 72 79 2d 3e 64 5f    if( pEntry->d_
06f0: 6e 61 6d 65 5b 30 5d 3d 3d 27 2e 27 20 29 20 63  name[0]=='.' ) c
0700: 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 7a  ontinue;.      z
0710: 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 28 7a  Path = mprintf(z
0720: 46 6f 72 6d 61 74 2c 20 7a 4f 72 69 67 69 6e 2c  Format, zOrigin,
0730: 20 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d 65 29   pEntry->d_name)
0740: 3b 0a 20 20 20 20 20 20 69 66 28 20 66 69 6c 65  ;.      if( file
0750: 5f 69 73 64 69 72 28 7a 50 61 74 68 29 3d 3d 31  _isdir(zPath)==1
0760: 20 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 75 6e   ){.        coun
0770: 74 20 2b 3d 20 69 6d 70 6f 72 74 5f 6f 72 69 67  t += import_orig
0780: 69 6e 28 7a 50 61 74 68 29 3b 0a 20 20 20 20 20  in(zPath);.     
0790: 20 7d 65 6c 73 65 20 69 66 28 20 66 69 6c 65 5f   }else if( file_
07a0: 69 73 66 69 6c 65 28 7a 50 61 74 68 29 20 29 7b  isfile(zPath) ){
07b0: 0a 09 42 6c 6f 62 20 7a 49 6e 3b 0a 09 62 6c 6f  ..Blob zIn;..blo
07c0: 62 5f 72 65 61 64 5f 66 72 6f 6d 5f 66 69 6c 65  b_read_from_file
07d0: 20 28 26 7a 49 6e 2c 7a 50 61 74 68 29 3b 0a 09   (&zIn,zPath);..
07e0: 63 6f 6e 74 65 6e 74 5f 70 75 74 20 28 26 7a 49  content_put (&zI
07f0: 6e 2c 20 30 2c 20 30 29 3b 0a 09 62 6c 6f 62 5f  n, 0, 0);..blob_
0800: 72 65 73 65 74 20 28 26 7a 49 6e 29 3b 0a 09 63  reset (&zIn);..c
0810: 6f 75 6e 74 2b 2b 3b 0a 20 20 20 20 20 20 7d 0a  ount++;.      }.
0820: 20 20 20 20 20 20 66 72 65 65 20 28 7a 50 61 74        free (zPat
0830: 68 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20  h);.    }.  }.  
0840: 63 6c 6f 73 65 64 69 72 28 64 29 3b 0a 20 20 72  closedir(d);.  r
0850: 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d 0a 0a  eturn count;.}..
0860: 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 64  /*.** COMMAND: d
0870: 65 63 6f 6e 73 74 72 75 63 74 20 0a 2a 2a 20 55  econstruct .** U
0880: 73 61 67 65 20 25 66 6f 73 73 69 6c 20 64 65 63  sage %fossil dec
0890: 6f 6e 73 74 72 75 63 74 20 3f 2d 52 7c 2d 2d 72  onstruct ?-R|--r
08a0: 65 70 6f 73 69 74 6f 72 79 20 52 45 50 4f 53 49  epository REPOSI
08b0: 54 4f 52 59 3f 20 44 45 53 54 49 4e 41 54 49 4f  TORY? DESTINATIO
08c0: 4e 0a 2a 2a 0a 2a 2a 20 50 6f 70 75 6c 61 74 65  N.**.** Populate
08d0: 73 20 74 68 65 20 69 6e 64 69 63 61 74 65 64 20  s the indicated 
08e0: 44 45 53 54 49 4e 41 54 49 4f 4e 20 64 69 72 65  DESTINATION dire
08f0: 63 74 6f 72 79 20 77 69 74 68 20 63 6f 70 69 65  ctory with copie
0900: 73 20 6f 66 20 61 6c 6c 0a 2a 2a 20 66 69 6c 65  s of all.** file
0910: 73 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 68  s contained with
0920: 69 6e 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72  in the repositor
0930: 79 2e 20 20 46 69 6c 65 73 20 61 72 65 20 6e 61  y.  Files are na
0940: 6d 65 64 20 41 41 2f 62 62 62 62 62 0a 2a 2a 20  med AA/bbbbb.** 
0950: 77 68 65 72 65 20 41 41 20 69 73 20 74 68 65 20  where AA is the 
0960: 66 69 72 73 74 20 32 20 63 68 61 72 61 63 74 65  first 2 characte
0970: 72 73 20 6f 66 20 74 68 65 20 75 75 69 64 20 61  rs of the uuid a
0980: 6e 64 20 62 62 62 62 62 20 69 73 20 74 68 65 0a  nd bbbbb is the.
0990: 2a 2a 20 72 65 6d 61 69 6e 69 6e 67 20 33 38 20  ** remaining 38 
09a0: 63 68 61 72 61 63 74 65 72 73 2e 0a 2a 2f 0a 0a  characters..*/..
09b0: 76 6f 69 64 20 64 65 63 6f 6e 73 74 72 75 63 74  void deconstruct
09c0: 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f  _cmd(void){.  co
09d0: 6e 73 74 20 63 68 61 72 2a 20 7a 44 65 73 74 69  nst char* zDesti
09e0: 6e 61 74 69 6f 6e 3b 0a 20 20 42 6c 6f 62 20 7a  nation;.  Blob z
09f0: 4f 75 74 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 20  Out;.  Stmt q;. 
0a00: 20 69 66 28 20 28 67 2e 61 72 67 63 20 21 3d 20   if( (g.argc != 
0a10: 33 29 20 26 26 20 28 67 2e 61 72 67 63 20 21 3d  3) && (g.argc !=
0a20: 20 35 29 20 29 7b 0a 20 20 20 20 75 73 61 67 65   5) ){.    usage
0a30: 20 28 22 3f 2d 52 7c 2d 2d 72 65 70 6f 73 69 74   ("?-R|--reposit
0a40: 6f 72 79 20 52 45 50 4f 53 49 54 4f 52 59 3f 20  ory REPOSITORY? 
0a50: 44 45 53 54 49 4e 41 54 49 4f 4e 22 29 3b 0a 20  DESTINATION");. 
0a60: 20 7d 0a 20 20 64 62 5f 66 69 6e 64 5f 61 6e 64   }.  db_find_and
0a70: 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79  _open_repository
0a80: 20 28 29 3b 0a 20 20 7a 44 65 73 74 69 6e 61 74   ();.  zDestinat
0a90: 69 6f 6e 20 3d 20 67 2e 61 72 67 76 5b 67 2e 61  ion = g.argv[g.a
0aa0: 72 67 63 2d 31 5d 3b 0a 20 20 69 66 28 20 21 66  rgc-1];.  if( !f
0ab0: 69 6c 65 5f 69 73 64 69 72 20 28 7a 44 65 73 74  ile_isdir (zDest
0ac0: 69 6e 61 74 69 6f 6e 29 20 29 7b 0a 20 20 20 20  ination) ){.    
0ad0: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 6e 6f  fossil_panic("no
0ae0: 74 20 61 20 64 69 72 65 63 74 6f 72 79 3a 20 25  t a directory: %
0af0: 73 22 2c 20 7a 44 65 73 74 69 6e 61 74 69 6f 6e  s", zDestination
0b00: 29 3b 0a 20 20 7d 0a 20 20 2f 2a 20 49 74 65 72  );.  }.  /* Iter
0b10: 61 74 65 20 6f 76 65 72 20 61 6c 6c 20 62 6c 6f  ate over all blo
0b20: 62 73 20 69 6e 20 74 68 65 20 72 65 70 6f 73 69  bs in the reposi
0b30: 74 6f 72 79 2c 20 72 65 74 72 69 65 76 65 20 74  tory, retrieve t
0b40: 68 65 69 72 0a 20 20 20 2a 20 63 6f 6e 74 65 6e  heir.   * conten
0b50: 74 73 2c 20 61 6e 64 20 77 72 69 74 65 20 74 68  ts, and write th
0b60: 65 6d 20 74 6f 20 61 20 66 69 6c 65 20 77 69 74  em to a file wit
0b70: 68 20 61 20 6e 61 6d 65 20 62 61 73 65 64 20 6f  h a name based o
0b80: 6e 20 74 68 65 69 72 0a 20 20 20 2a 20 75 75 69  n their.   * uui
0b90: 64 2e 20 4e 6f 74 65 3a 20 4e 6f 6e 2d 77 72 69  d. Note: Non-wri
0ba0: 74 61 62 6c 65 20 64 65 73 74 69 6e 61 74 69 6f  table destinatio
0bb0: 6e 20 63 61 75 73 65 73 20 62 61 69 6c 2d 6f 75  n causes bail-ou
0bc0: 74 20 69 6e 20 74 68 65 20 66 69 72 73 74 0a 20  t in the first. 
0bd0: 20 20 2a 20 63 61 6c 6c 20 6f 66 20 62 6c 6f 62    * call of blob
0be0: 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 2e 0a  _write_to_file..
0bf0: 20 20 20 2a 2f 0a 20 20 64 62 5f 70 72 65 70 61     */.  db_prepa
0c00: 72 65 28 26 71 2c 20 22 53 45 4c 45 43 54 20 72  re(&q, "SELECT r
0c10: 69 64 2c 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f  id,uuid FROM blo
0c20: 62 22 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62  b");.  while( db
0c30: 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54  _step(&q)==SQLIT
0c40: 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 69 6e 74  E_ROW ){.    int
0c50: 20 20 20 20 20 20 20 20 20 72 69 64 20 20 20 3d           rid   =
0c60: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 20 28   db_column_int (
0c70: 26 71 2c 20 30 29 3b 0a 20 20 20 20 63 6f 6e 73  &q, 0);.    cons
0c80: 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d 20  t char *zUuid = 
0c90: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26  db_column_text(&
0ca0: 71 2c 20 31 29 3b 0a 20 20 20 20 63 68 61 72 20  q, 1);.    char 
0cb0: 20 20 20 20 20 20 2a 7a 46 69 6c 65 20 3d 20 6d        *zFile = m
0cc0: 70 72 69 6e 74 66 20 28 22 25 73 2f 25 2e 32 73  printf ("%s/%.2s
0cd0: 2f 25 73 22 2c 20 7a 44 65 73 74 69 6e 61 74 69  /%s", zDestinati
0ce0: 6f 6e 2c 20 7a 55 75 69 64 2c 20 7a 55 75 69 64  on, zUuid, zUuid
0cf0: 20 2b 20 32 29 3b 0a 20 20 20 20 63 6f 6e 74 65   + 2);.    conte
0d00: 6e 74 5f 67 65 74 20 28 72 69 64 2c 26 7a 4f 75  nt_get (rid,&zOu
0d10: 74 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 77 72 69  t);.    blob_wri
0d20: 74 65 5f 74 6f 5f 66 69 6c 65 20 28 26 7a 4f 75  te_to_file (&zOu
0d30: 74 2c 7a 46 69 6c 65 29 3b 0a 20 20 20 20 62 6c  t,zFile);.    bl
0d40: 6f 62 5f 72 65 73 65 74 20 28 26 7a 4f 75 74 29  ob_reset (&zOut)
0d50: 3b 0a 20 20 20 20 66 72 65 65 28 7a 46 69 6c 65  ;.    free(zFile
0d60: 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61  );.  }.  db_fina
0d70: 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a  lize(&q);.}../*.
0d80: 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 72 65 63 6f  ** COMMAND: reco
0d90: 6e 73 74 72 75 63 74 20 0a 2a 2a 20 55 73 61 67  nstruct .** Usag
0da0: 65 20 25 66 6f 73 73 69 6c 20 72 65 63 6f 6e 73  e %fossil recons
0db0: 74 72 75 63 74 20 52 45 50 4f 53 49 54 4f 52 59  truct REPOSITORY
0dc0: 20 4f 52 49 47 49 4e 0a 2a 2a 0a 2a 2a 20 43 72   ORIGIN.**.** Cr
0dd0: 65 61 74 65 73 20 74 68 65 20 52 45 50 4f 53 49  eates the REPOSI
0de0: 54 4f 52 59 20 61 6e 64 20 70 6f 70 75 6c 61 74  TORY and populat
0df0: 65 73 20 69 74 20 77 69 74 68 20 74 68 65 20 66  es it with the f
0e00: 69 6c 65 73 20 69 6e 20 74 68 65 0a 2a 2a 20 69  iles in the.** i
0e10: 6e 64 69 63 61 74 65 64 20 4f 52 49 47 49 4e 20  ndicated ORIGIN 
0e20: 64 69 72 65 63 74 6f 72 79 2e 0a 2a 2f 0a 0a 76  directory..*/..v
0e30: 6f 69 64 20 72 65 63 6f 6e 73 74 72 75 63 74 5f  oid reconstruct_
0e40: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e  cmd(void){.  con
0e50: 73 74 20 63 68 61 72 2a 20 7a 4f 72 69 67 69 6e  st char* zOrigin
0e60: 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 2a 20  ;.  const char* 
0e70: 7a 52 65 70 6f 73 69 74 6f 72 79 3b 0a 20 20 69  zRepository;.  i
0e80: 6e 74 20 66 69 6c 65 43 6e 74 3b 0a 20 20 69 6e  nt fileCnt;.  in
0e90: 74 20 65 72 72 43 6e 74 3b 0a 0a 20 20 69 66 28  t errCnt;..  if(
0ea0: 20 67 2e 61 72 67 63 20 21 3d 20 34 20 29 7b 0a   g.argc != 4 ){.
0eb0: 20 20 20 20 75 73 61 67 65 20 28 22 52 45 50 4f      usage ("REPO
0ec0: 53 49 54 4f 52 59 20 4f 52 49 47 49 4e 22 29 3b  SITORY ORIGIN");
0ed0: 0a 20 20 7d 0a 20 20 7a 52 65 70 6f 73 69 74 6f  .  }.  zReposito
0ee0: 72 79 20 3d 20 67 2e 61 72 67 76 5b 32 5d 3b 0a  ry = g.argv[2];.
0ef0: 20 20 7a 4f 72 69 67 69 6e 20 20 20 20 20 3d 20    zOrigin     = 
0f00: 67 2e 61 72 67 76 5b 33 5d 3b 0a 20 20 69 66 28  g.argv[3];.  if(
0f10: 20 21 66 69 6c 65 5f 69 73 64 69 72 20 28 7a 4f   !file_isdir (zO
0f20: 72 69 67 69 6e 29 20 29 7b 0a 20 20 20 20 66 6f  rigin) ){.    fo
0f30: 73 73 69 6c 5f 70 61 6e 69 63 28 22 6e 6f 74 20  ssil_panic("not 
0f40: 61 20 64 69 72 65 63 74 6f 72 79 3a 20 25 73 22  a directory: %s"
0f50: 2c 20 7a 4f 72 69 67 69 6e 29 3b 0a 20 20 7d 0a  , zOrigin);.  }.
0f60: 0a 20 20 2f 2a 20 43 72 65 61 74 65 20 74 68 65  .  /* Create the
0f70: 20 66 6f 75 6e 64 61 74 69 6f 6e 20 2a 2f 0a 20   foundation */. 
0f80: 20 64 62 5f 63 72 65 61 74 65 5f 72 65 70 6f 73   db_create_repos
0f90: 69 74 6f 72 79 28 7a 52 65 70 6f 73 69 74 6f 72  itory(zRepositor
0fa0: 79 29 3b 0a 20 20 64 62 5f 6f 70 65 6e 5f 72 65  y);.  db_open_re
0fb0: 70 6f 73 69 74 6f 72 79 28 7a 52 65 70 6f 73 69  pository(zReposi
0fc0: 74 6f 72 79 29 3b 0a 20 20 64 62 5f 6f 70 65 6e  tory);.  db_open
0fd0: 5f 63 6f 6e 66 69 67 28 29 3b 0a 20 20 64 62 5f  _config();.  db_
0fe0: 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f  begin_transactio
0ff0: 6e 28 29 3b 0a 0a 20 20 64 62 5f 69 6e 69 74 69  n();..  db_initi
1000: 61 6c 5f 73 65 74 75 70 28 30 2c 20 31 29 3b 0a  al_setup(0, 1);.
1010: 0a 20 20 70 72 69 6e 74 66 28 22 70 72 6f 6a 65  .  printf("proje
1020: 63 74 2d 69 64 3a 20 25 73 5c 6e 22 2c 20 64 62  ct-id: %s\n", db
1030: 5f 67 65 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f  _get("project-co
1040: 64 65 22 2c 20 30 29 29 3b 0a 20 20 70 72 69 6e  de", 0));.  prin
1050: 74 66 28 22 73 65 72 76 65 72 2d 69 64 3a 20 20  tf("server-id:  
1060: 25 73 5c 6e 22 2c 20 64 62 5f 67 65 74 28 22 73  %s\n", db_get("s
1070: 65 72 76 65 72 2d 63 6f 64 65 22 2c 20 30 29 29  erver-code", 0))
1080: 3b 0a 20 20 70 72 69 6e 74 66 28 22 61 64 6d 69  ;.  printf("admi
1090: 6e 2d 75 73 65 72 3a 20 25 73 20 28 6e 6f 20 70  n-user: %s (no p
10a0: 61 73 73 77 6f 72 64 20 73 65 74 20 79 65 74 21  assword set yet!
10b0: 29 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b  )\n", g.zLogin);
10c0: 0a 20 20 70 72 69 6e 74 66 28 22 62 61 73 65 6c  .  printf("basel
10d0: 69 6e 65 3a 20 20 20 25 73 5c 6e 22 2c 20 64 62  ine:   %s\n", db
10e0: 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54  _text(0, "SELECT
10f0: 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 22   uuid FROM blob"
1100: 29 29 3b 0a 0a 20 20 2f 2a 20 53 63 61 6e 20 6f  ));..  /* Scan o
1110: 72 69 67 69 6e 20 61 6e 64 20 69 6e 73 65 72 74  rigin and insert
1120: 20 61 6c 6c 20 66 69 6c 65 73 20 66 6f 75 6e 64   all files found
1130: 20 69 6e 73 69 64 65 20 2a 2f 0a 20 20 66 69 6c   inside */.  fil
1140: 65 43 6e 74 20 3d 20 69 6d 70 6f 72 74 5f 6f 72  eCnt = import_or
1150: 69 67 69 6e 20 28 7a 4f 72 69 67 69 6e 29 3b 0a  igin (zOrigin);.
1160: 0a 20 20 70 72 69 6e 74 66 28 22 69 6d 70 6f 72  .  printf("impor
1170: 74 65 64 3a 20 20 20 25 64 20 25 73 5c 6e 22 2c  ted:   %d %s\n",
1180: 20 66 69 6c 65 43 6e 74 2c 20 66 69 6c 65 43 6e   fileCnt, fileCn
1190: 74 20 3d 3d 20 31 20 3f 0a 09 20 22 66 69 6c 65  t == 1 ?.. "file
11a0: 22 20 3a 20 22 66 69 6c 65 73 22 29 3b 0a 0a 20  " : "files");.. 
11b0: 20 2f 2a 20 46 69 6e 61 6c 69 7a 65 20 74 68 65   /* Finalize the
11c0: 20 72 65 70 6f 73 69 74 6f 72 79 2c 20 72 65 62   repository, reb
11d0: 75 69 6c 64 20 74 68 65 20 64 65 72 69 76 65 64  uild the derived
11e0: 20 74 61 62 6c 65 73 20 2a 2f 0a 20 20 65 72 72   tables */.  err
11f0: 43 6e 74 20 3d 20 72 65 62 75 69 6c 64 5f 64 62  Cnt = rebuild_db
1200: 28 30 29 3b 0a 0a 20 20 69 66 28 20 65 72 72 43  (0);..  if( errC
1210: 6e 74 20 29 7b 0a 20 20 20 20 70 72 69 6e 74 66  nt ){.    printf
1220: 28 22 25 64 20 25 73 2e 20 52 6f 6c 6c 69 6e 67  ("%d %s. Rolling
1230: 20 62 61 63 6b 20 63 68 61 6e 67 65 73 2e 5c 6e   back changes.\n
1240: 22 2c 20 65 72 72 43 6e 74 2c 20 65 72 72 43 6e  ", errCnt, errCn
1250: 74 20 3d 3d 20 31 20 3f 0a 09 20 20 20 22 65 72  t == 1 ?..   "er
1260: 72 6f 72 22 20 3a 20 22 65 72 72 6f 72 73 22 29  ror" : "errors")
1270: 3b 0a 20 20 20 20 64 62 5f 65 6e 64 5f 74 72 61  ;.    db_end_tra
1280: 6e 73 61 63 74 69 6f 6e 28 31 29 3b 0a 20 20 7d  nsaction(1);.  }
1290: 65 6c 73 65 7b 0a 20 20 20 20 64 62 5f 65 6e 64  else{.    db_end
12a0: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b  _transaction(0);
12b0: 0a 20 20 7d 0a 7d 0a                             .  }.}.