Overview
SHA1 Hash: | 9236f0c086010e7c7704fccdc5845e7c86f80406 |
---|---|
Date: | 2008-10-05 12:34:14 |
User: | drh |
Comment: | Get cloning working for local files without the use of network I/O.
Ticket |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/clone.c from [06872ed5c0] to [effa624f67].
@@ -45,47 +45,41 @@ db_open_config(); if( file_size(g.argv[3])>0 ){ fossil_panic("file already exists: %s", g.argv[3]); } url_parse(g.argv[2]); - db_create_repository(g.argv[3]); - db_open_repository(g.argv[3]); - db_begin_transaction(); - db_initial_setup(0, 0); - user_select(); - db_set("content-schema", CONTENT_SCHEMA, 0); - db_set("aux-schema", AUX_SCHEMA, 0); - if( !g.urlIsFile ){ - db_set("last-sync-url", g.argv[2], 0); - } - db_multi_exec( - "INSERT INTO config(name,value)" - " VALUES('server-code', lower(hex(randomblob(20))));" - ); if( g.urlIsFile ){ - Stmt q; - db_multi_exec("ATTACH DATABASE %Q AS orig", g.urlName); - db_prepare(&q, - "SELECT name FROM orig.sqlite_master" - " WHERE type='table'" + file_copy(g.urlName, g.argv[3]); + db_close(); + db_open_repository(g.argv[3]); + db_multi_exec( + "REPLACE INTO config(name,value)" + " VALUES('server-code', lower(hex(randomblob(20))));" ); - while( db_step(&q)==SQLITE_ROW ){ - const char *zTab = db_column_text(&q, 0); - db_multi_exec("INSERT OR IGNORE INTO %Q SELECT * FROM orig.%Q", - zTab, zTab); - } - db_finalize(&q); + printf("Repository cloned into %s\n", g.argv[3]); }else{ + db_create_repository(g.argv[3]); + db_open_repository(g.argv[3]); + db_begin_transaction(); + db_initial_setup(0, 0); + user_select(); + db_set("content-schema", CONTENT_SCHEMA, 0); + db_set("aux-schema", AUX_SCHEMA, 0); + db_set("last-sync-url", g.argv[2], 0); + db_multi_exec( + "REPLACE INTO config(name,value)" + " VALUES('server-code', lower(hex(randomblob(20))));" + ); url_enable_proxy(0); g.xlinkClusterOnly = 1; client_sync(0,0,1,CONFIGSET_ALL); g.xlinkClusterOnly = 0; - } - verify_cancel(); - db_end_transaction(0); - db_close(); - db_open_repository(g.argv[3]); + verify_cancel(); + db_end_transaction(0); + db_close(); + db_open_repository(g.argv[3]); + } db_begin_transaction(); printf("Rebuilding repository meta-data...\n"); rebuild_db(0, 1); db_end_transaction(0); }
Modified src/file.c from [4b43b0dc29] to [d20fa8930e].
@@ -50,10 +50,28 @@ struct stat buf; if( stat(zFilename, &buf)!=0 ){ return -1; } return buf.st_mtime; +} + +/* +** Copy the content of a file from one place to another. +*/ +void file_copy(const char *zFrom, const char *zTo){ + FILE *in, *out; + int got; + char zBuf[8192]; + in = fopen(zFrom, "rb"); + if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom); + out = fopen(zTo, "wb"); + if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo); + while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){ + fwrite(zBuf, 1, got, out); + } + fclose(in); + fclose(out); } /* ** Return TRUE if the named file is an ordinary file. Return false ** for directories, devices, fifos, symlinks, etc.