Fossil SCM

Add support for "file:" URLs on push, pull, and sync.

drh 2009-04-11 12:51 trunk
Commit 945ecd1a8bcb94e1def1f34809a7da7980d11517
--- src/clone.c
+++ src/clone.c
@@ -55,10 +55,13 @@
5555
db_open_config();
5656
db_record_repository_filename(g.argv[3]);
5757
db_multi_exec(
5858
"REPLACE INTO config(name,value)"
5959
" VALUES('server-code', lower(hex(randomblob(20))));"
60
+ "REPLACE INTO config(name,value)"
61
+ " VALUES('last-sync-url', 'file://%q');",
62
+ g.urlName
6063
);
6164
g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
6265
if( g.zLogin==0 ){
6366
db_create_default_users(1);
6467
}
6568
--- src/clone.c
+++ src/clone.c
@@ -55,10 +55,13 @@
55 db_open_config();
56 db_record_repository_filename(g.argv[3]);
57 db_multi_exec(
58 "REPLACE INTO config(name,value)"
59 " VALUES('server-code', lower(hex(randomblob(20))));"
 
 
 
60 );
61 g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
62 if( g.zLogin==0 ){
63 db_create_default_users(1);
64 }
65
--- src/clone.c
+++ src/clone.c
@@ -55,10 +55,13 @@
55 db_open_config();
56 db_record_repository_filename(g.argv[3]);
57 db_multi_exec(
58 "REPLACE INTO config(name,value)"
59 " VALUES('server-code', lower(hex(randomblob(20))));"
60 "REPLACE INTO config(name,value)"
61 " VALUES('last-sync-url', 'file://%q');",
62 g.urlName
63 );
64 g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
65 if( g.zLogin==0 ){
66 db_create_default_users(1);
67 }
68
--- src/http_transport.c
+++ src/http_transport.c
@@ -31,15 +31,18 @@
3131
3232
/*
3333
** State information
3434
*/
3535
static struct {
36
- int isOpen; /* True when the transport layer is open */
37
- char *pBuf; /* Buffer used to hold the reply */
38
- int nAlloc; /* Space allocated for transportBuf[] */
39
- int nUsed ; /* Space of transportBuf[] used */
40
- int iCursor; /* Next unread by in transportBuf[] */
36
+ int isOpen; /* True when the transport layer is open */
37
+ char *pBuf; /* Buffer used to hold the reply */
38
+ int nAlloc; /* Space allocated for transportBuf[] */
39
+ int nUsed ; /* Space of transportBuf[] used */
40
+ int iCursor; /* Next unread by in transportBuf[] */
41
+ FILE *pFile; /* File I/O for FILE: */
42
+ char *zOutFile; /* Name of outbound file for FILE: */
43
+ char *zInFile; /* Name of inbound file for FILE: */
4144
} transport = {
4245
0, 0, 0, 0, 0
4346
};
4447
4548
/*
@@ -64,12 +67,21 @@
6467
if( transport.isOpen==0 ){
6568
if( g.urlIsHttps ){
6669
socket_set_errmsg("HTTPS: is not yet implemented");
6770
rc = 1;
6871
}else if( g.urlIsFile ){
69
- socket_set_errmsg("FILE: is not yet implemented");
70
- rc = 1;
72
+ sqlite3_uint64 iRandId;
73
+ sqlite3_randomness(sizeof(iRandId), &iRandId);
74
+ transport.zOutFile = mprintf("%s-%llu-out.http",
75
+ g.zRepositoryName, iRandId);
76
+ transport.zInFile = mprintf("%s-%llu-in.http",
77
+ g.zRepositoryName, iRandId);
78
+ transport.pFile = fopen(transport.zOutFile, "wb");
79
+ if( transport.pFile==0 ){
80
+ fossil_fatal("cannot output temporary file: %s", transport.zOutFile);
81
+ }
82
+ transport.isOpen = 1;
7183
}else{
7284
rc = socket_open();
7385
if( rc==0 ) transport.isOpen = 1;
7486
}
7587
}
@@ -87,11 +99,18 @@
8799
transport.nUsed = 0;
88100
transport.iCursor = 0;
89101
if( g.urlIsHttps ){
90102
/* TBD */
91103
}else if( g.urlIsFile ){
92
- /* TBD */
104
+ if( transport.pFile ){
105
+ fclose(transport.pFile);
106
+ transport.pFile = 0;
107
+ }
108
+ unlink(transport.zInFile);
109
+ free(transport.zInFile);
110
+ unlink(transport.zOutFile);
111
+ free(transport.zOutFile);
93112
}else{
94113
socket_close();
95114
}
96115
transport.isOpen = 0;
97116
}
@@ -99,17 +118,17 @@
99118
100119
/*
101120
** Send content over the wire.
102121
*/
103122
void transport_send(Blob *toSend){
123
+ char *z = blob_buffer(toSend);
124
+ int n = blob_size(toSend);
104125
if( g.urlIsHttps ){
105126
/* TBD */
106127
}else if( g.urlIsFile ){
107
- /* TBD */
128
+ fwrite(z, 1, n, transport.pFile);
108129
}else{
109
- char *z = blob_buffer(toSend);
110
- int n = blob_size(toSend);
111130
int sent;
112131
while( n>0 ){
113132
sent = socket_send(0, z, n);
114133
if( sent<=0 ) break;
115134
n -= sent;
@@ -121,11 +140,18 @@
121140
** This routine is called when the outbound message is complete and
122141
** it is time to being recieving a reply.
123142
*/
124143
void transport_flip(void){
125144
if( g.urlIsFile ){
126
- /* run "fossil http" to process the outbound message */
145
+ char *zCmd;
146
+ fclose(transport.pFile);
147
+ zCmd = mprintf("\"%s\" http \"%s\" \"%s\" \"%s\" 127.0.0.1",
148
+ g.argv[0], g.zRepositoryName, transport.zOutFile, transport.zInFile
149
+ );
150
+ system(zCmd);
151
+ free(zCmd);
152
+ transport.pFile = fopen(transport.zInFile, "rb");
127153
}
128154
}
129155
130156
/*
131157
** This routine is called when the inbound message has been received
@@ -163,12 +189,11 @@
163189
int got;
164190
if( g.urlIsHttps ){
165191
/* TBD */
166192
got = 0;
167193
}else if( g.urlIsFile ){
168
- /* TBD */
169
- got = 0;
194
+ got = fread(zBuf, 0, N, transport.pFile);
170195
}else{
171196
got = socket_receive(0, zBuf, N);
172197
}
173198
if( got>0 ){
174199
nByte += got;
175200
--- src/http_transport.c
+++ src/http_transport.c
@@ -31,15 +31,18 @@
31
32 /*
33 ** State information
34 */
35 static struct {
36 int isOpen; /* True when the transport layer is open */
37 char *pBuf; /* Buffer used to hold the reply */
38 int nAlloc; /* Space allocated for transportBuf[] */
39 int nUsed ; /* Space of transportBuf[] used */
40 int iCursor; /* Next unread by in transportBuf[] */
 
 
 
41 } transport = {
42 0, 0, 0, 0, 0
43 };
44
45 /*
@@ -64,12 +67,21 @@
64 if( transport.isOpen==0 ){
65 if( g.urlIsHttps ){
66 socket_set_errmsg("HTTPS: is not yet implemented");
67 rc = 1;
68 }else if( g.urlIsFile ){
69 socket_set_errmsg("FILE: is not yet implemented");
70 rc = 1;
 
 
 
 
 
 
 
 
 
71 }else{
72 rc = socket_open();
73 if( rc==0 ) transport.isOpen = 1;
74 }
75 }
@@ -87,11 +99,18 @@
87 transport.nUsed = 0;
88 transport.iCursor = 0;
89 if( g.urlIsHttps ){
90 /* TBD */
91 }else if( g.urlIsFile ){
92 /* TBD */
 
 
 
 
 
 
 
93 }else{
94 socket_close();
95 }
96 transport.isOpen = 0;
97 }
@@ -99,17 +118,17 @@
99
100 /*
101 ** Send content over the wire.
102 */
103 void transport_send(Blob *toSend){
 
 
104 if( g.urlIsHttps ){
105 /* TBD */
106 }else if( g.urlIsFile ){
107 /* TBD */
108 }else{
109 char *z = blob_buffer(toSend);
110 int n = blob_size(toSend);
111 int sent;
112 while( n>0 ){
113 sent = socket_send(0, z, n);
114 if( sent<=0 ) break;
115 n -= sent;
@@ -121,11 +140,18 @@
121 ** This routine is called when the outbound message is complete and
122 ** it is time to being recieving a reply.
123 */
124 void transport_flip(void){
125 if( g.urlIsFile ){
126 /* run "fossil http" to process the outbound message */
 
 
 
 
 
 
 
127 }
128 }
129
130 /*
131 ** This routine is called when the inbound message has been received
@@ -163,12 +189,11 @@
163 int got;
164 if( g.urlIsHttps ){
165 /* TBD */
166 got = 0;
167 }else if( g.urlIsFile ){
168 /* TBD */
169 got = 0;
170 }else{
171 got = socket_receive(0, zBuf, N);
172 }
173 if( got>0 ){
174 nByte += got;
175
--- src/http_transport.c
+++ src/http_transport.c
@@ -31,15 +31,18 @@
31
32 /*
33 ** State information
34 */
35 static struct {
36 int isOpen; /* True when the transport layer is open */
37 char *pBuf; /* Buffer used to hold the reply */
38 int nAlloc; /* Space allocated for transportBuf[] */
39 int nUsed ; /* Space of transportBuf[] used */
40 int iCursor; /* Next unread by in transportBuf[] */
41 FILE *pFile; /* File I/O for FILE: */
42 char *zOutFile; /* Name of outbound file for FILE: */
43 char *zInFile; /* Name of inbound file for FILE: */
44 } transport = {
45 0, 0, 0, 0, 0
46 };
47
48 /*
@@ -64,12 +67,21 @@
67 if( transport.isOpen==0 ){
68 if( g.urlIsHttps ){
69 socket_set_errmsg("HTTPS: is not yet implemented");
70 rc = 1;
71 }else if( g.urlIsFile ){
72 sqlite3_uint64 iRandId;
73 sqlite3_randomness(sizeof(iRandId), &iRandId);
74 transport.zOutFile = mprintf("%s-%llu-out.http",
75 g.zRepositoryName, iRandId);
76 transport.zInFile = mprintf("%s-%llu-in.http",
77 g.zRepositoryName, iRandId);
78 transport.pFile = fopen(transport.zOutFile, "wb");
79 if( transport.pFile==0 ){
80 fossil_fatal("cannot output temporary file: %s", transport.zOutFile);
81 }
82 transport.isOpen = 1;
83 }else{
84 rc = socket_open();
85 if( rc==0 ) transport.isOpen = 1;
86 }
87 }
@@ -87,11 +99,18 @@
99 transport.nUsed = 0;
100 transport.iCursor = 0;
101 if( g.urlIsHttps ){
102 /* TBD */
103 }else if( g.urlIsFile ){
104 if( transport.pFile ){
105 fclose(transport.pFile);
106 transport.pFile = 0;
107 }
108 unlink(transport.zInFile);
109 free(transport.zInFile);
110 unlink(transport.zOutFile);
111 free(transport.zOutFile);
112 }else{
113 socket_close();
114 }
115 transport.isOpen = 0;
116 }
@@ -99,17 +118,17 @@
118
119 /*
120 ** Send content over the wire.
121 */
122 void transport_send(Blob *toSend){
123 char *z = blob_buffer(toSend);
124 int n = blob_size(toSend);
125 if( g.urlIsHttps ){
126 /* TBD */
127 }else if( g.urlIsFile ){
128 fwrite(z, 1, n, transport.pFile);
129 }else{
 
 
130 int sent;
131 while( n>0 ){
132 sent = socket_send(0, z, n);
133 if( sent<=0 ) break;
134 n -= sent;
@@ -121,11 +140,18 @@
140 ** This routine is called when the outbound message is complete and
141 ** it is time to being recieving a reply.
142 */
143 void transport_flip(void){
144 if( g.urlIsFile ){
145 char *zCmd;
146 fclose(transport.pFile);
147 zCmd = mprintf("\"%s\" http \"%s\" \"%s\" \"%s\" 127.0.0.1",
148 g.argv[0], g.zRepositoryName, transport.zOutFile, transport.zInFile
149 );
150 system(zCmd);
151 free(zCmd);
152 transport.pFile = fopen(transport.zInFile, "rb");
153 }
154 }
155
156 /*
157 ** This routine is called when the inbound message has been received
@@ -163,12 +189,11 @@
189 int got;
190 if( g.urlIsHttps ){
191 /* TBD */
192 got = 0;
193 }else if( g.urlIsFile ){
194 got = fread(zBuf, 0, N, transport.pFile);
 
195 }else{
196 got = socket_receive(0, zBuf, N);
197 }
198 if( got>0 ){
199 nByte += got;
200
+2
--- src/url.c
+++ src/url.c
@@ -116,10 +116,12 @@
116116
if( g.urlIsFile ){
117117
Blob cfile;
118118
dehttpize(zFile);
119119
file_canonical_name(zFile, &cfile);
120120
free(zFile);
121
+ g.urlProtocol = "file";
122
+ g.urlPath = "";
121123
g.urlName = mprintf("%b", &cfile);
122124
g.urlCanonical = mprintf("file://%T", g.urlName);
123125
blob_reset(&cfile);
124126
}
125127
}
126128
--- src/url.c
+++ src/url.c
@@ -116,10 +116,12 @@
116 if( g.urlIsFile ){
117 Blob cfile;
118 dehttpize(zFile);
119 file_canonical_name(zFile, &cfile);
120 free(zFile);
 
 
121 g.urlName = mprintf("%b", &cfile);
122 g.urlCanonical = mprintf("file://%T", g.urlName);
123 blob_reset(&cfile);
124 }
125 }
126
--- src/url.c
+++ src/url.c
@@ -116,10 +116,12 @@
116 if( g.urlIsFile ){
117 Blob cfile;
118 dehttpize(zFile);
119 file_canonical_name(zFile, &cfile);
120 free(zFile);
121 g.urlProtocol = "file";
122 g.urlPath = "";
123 g.urlName = mprintf("%b", &cfile);
124 g.urlCanonical = mprintf("file://%T", g.urlName);
125 blob_reset(&cfile);
126 }
127 }
128

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button