dbda8d6ce9 2007-07-21 drh: /* dbda8d6ce9 2007-07-21 drh: ** Copyright (c) 2007 D. Richard Hipp dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** This program is free software; you can redistribute it and/or dbda8d6ce9 2007-07-21 drh: ** modify it under the terms of the GNU General Public dbda8d6ce9 2007-07-21 drh: ** License version 2 as published by the Free Software Foundation. dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** This program is distributed in the hope that it will be useful, dbda8d6ce9 2007-07-21 drh: ** but WITHOUT ANY WARRANTY; without even the implied warranty of dbda8d6ce9 2007-07-21 drh: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dbda8d6ce9 2007-07-21 drh: ** General Public License for more details. dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** You should have received a copy of the GNU General Public dbda8d6ce9 2007-07-21 drh: ** License along with this library; if not, write to the dbda8d6ce9 2007-07-21 drh: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330, dbda8d6ce9 2007-07-21 drh: ** Boston, MA 02111-1307, USA. dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** Author contact information: dbda8d6ce9 2007-07-21 drh: ** drh@hwaci.com dbda8d6ce9 2007-07-21 drh: ** http://www.hwaci.com/drh/ dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ******************************************************************************* dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** This file contains code used to clone a repository dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: #include "config.h" dbda8d6ce9 2007-07-21 drh: #include "clone.h" dbda8d6ce9 2007-07-21 drh: #include <assert.h> dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: /* dbda8d6ce9 2007-07-21 drh: ** COMMAND: clone dbda8d6ce9 2007-07-21 drh: ** c9fdb846fb 2007-08-18 drh: ** Usage: %fossil clone URL FILENAME dbda8d6ce9 2007-07-21 drh: ** c9fdb846fb 2007-08-18 drh: ** Make a clone of a repository specified by URL in the local c9fdb846fb 2007-08-18 drh: ** file named FILENAME. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: void clone_cmd(void){ f652599003 2008-05-06 drh: url_proxy_options(); dbda8d6ce9 2007-07-21 drh: if( g.argc!=4 ){ dbda8d6ce9 2007-07-21 drh: usage("FILE-OR-URL NEW-REPOSITORY"); dbda8d6ce9 2007-07-21 drh: } cbe0ace8f3 2007-09-26 drh: db_open_config(); dbda8d6ce9 2007-07-21 drh: if( file_size(g.argv[3])>0 ){ dbda8d6ce9 2007-07-21 drh: fossil_panic("file already exists: %s", g.argv[3]); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: url_parse(g.argv[2]); 13b7ac16e4 2007-08-09 drh: if( g.urlIsFile ){ 9236f0c086 2008-10-05 drh: file_copy(g.urlName, g.argv[3]); 9236f0c086 2008-10-05 drh: db_close(); 9236f0c086 2008-10-05 drh: db_open_repository(g.argv[3]); 974f025c6e 2008-10-17 drh: db_open_config(); 2bd0690fe8 2008-10-17 drh: db_record_repository_filename(g.argv[3]); 9236f0c086 2008-10-05 drh: db_multi_exec( 9236f0c086 2008-10-05 drh: "REPLACE INTO config(name,value)" 9236f0c086 2008-10-05 drh: " VALUES('server-code', lower(hex(randomblob(20))));" 243e02bfbd 2008-05-18 drh: ); 9236f0c086 2008-10-05 drh: printf("Repository cloned into %s\n", g.argv[3]); 243e02bfbd 2008-05-18 drh: }else{ 9236f0c086 2008-10-05 drh: db_create_repository(g.argv[3]); 9236f0c086 2008-10-05 drh: db_open_repository(g.argv[3]); dbda8d6ce9 2007-07-21 drh: db_begin_transaction(); 2bd0690fe8 2008-10-17 drh: db_record_repository_filename(g.argv[3]); 9236f0c086 2008-10-05 drh: db_initial_setup(0, 0); 9236f0c086 2008-10-05 drh: user_select(); 9236f0c086 2008-10-05 drh: db_set("content-schema", CONTENT_SCHEMA, 0); 9236f0c086 2008-10-05 drh: db_set("aux-schema", AUX_SCHEMA, 0); 134e2aeccc 2007-09-28 drh: db_set("last-sync-url", g.argv[2], 0); 9236f0c086 2008-10-05 drh: db_multi_exec( 9236f0c086 2008-10-05 drh: "REPLACE INTO config(name,value)" 9236f0c086 2008-10-05 drh: " VALUES('server-code', lower(hex(randomblob(20))));" dbda8d6ce9 2007-07-21 drh: ); 676fdd088a 2008-05-01 drh: url_enable_proxy(0); 243e02bfbd 2008-05-18 drh: g.xlinkClusterOnly = 1; 6b0b57a924 2008-10-25 drh: client_sync(0,0,1,CONFIGSET_ALL,0); 243e02bfbd 2008-05-18 drh: g.xlinkClusterOnly = 0; 9236f0c086 2008-10-05 drh: verify_cancel(); dbda8d6ce9 2007-07-21 drh: db_end_transaction(0); 9236f0c086 2008-10-05 drh: db_close(); 9236f0c086 2008-10-05 drh: db_open_repository(g.argv[3]); dbda8d6ce9 2007-07-21 drh: } 243e02bfbd 2008-05-18 drh: db_begin_transaction(); 243e02bfbd 2008-05-18 drh: printf("Rebuilding repository meta-data...\n"); 243e02bfbd 2008-05-18 drh: rebuild_db(0, 1); 097479f99a 2007-09-26 drh: db_end_transaction(0); dbda8d6ce9 2007-07-21 drh: }