Fossil SCM

Improve error message when rejecting unversioned filenames

andygoth 2017-09-21 21:49 trunk
Commit 493e3bade9ae8dc61ece027603b8d4ce9106941be187e19b33a7bbed688c1af8
1 file changed +11 -4
--- src/unversioned.c
+++ src/unversioned.c
@@ -275,10 +275,11 @@
275275
}else{
276276
mtime = db_int(0, "SELECT strftime('%%s',%Q)", zMtime);
277277
if( mtime<=0 ) fossil_fatal("bad timestamp: %Q", zMtime);
278278
}
279279
if( memcmp(zCmd, "add", nCmd)==0 ){
280
+ const char *zError = 0;
280281
const char *zIn;
281282
const char *zAs;
282283
Blob file;
283284
int i;
284285
@@ -287,15 +288,21 @@
287288
verify_all_options();
288289
db_begin_transaction();
289290
content_rcvid_init("#!fossil unversioned add");
290291
for(i=3; i<g.argc; i++){
291292
zIn = zAs ? zAs : g.argv[i];
292
- if( zIn[0]==0 || zIn[0]=='/' || !file_is_simple_pathname(zIn,1) ){
293
- fossil_fatal("'%Q' is not an acceptable filename", zIn);
293
+ if( zIn[0]==0 ){
294
+ zError = "be empty string";
295
+ }else if( zIn[0]=='/' ){
296
+ zError = "be absolute";
297
+ }else if ( !file_is_simple_pathname(zIn,1) ){
298
+ zError = "contain complex paths";
299
+ }else if( contains_whitespace(zIn) ){
300
+ zError = "contain whitespace";
294301
}
295
- if( contains_whitespace(zIn) ){
296
- fossil_fatal("names of unversioned files may not contain whitespace");
302
+ if( zError ){
303
+ fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
297304
}
298305
blob_init(&file,0,0);
299306
blob_read_from_file(&file, g.argv[i]);
300307
unversioned_write(zIn, &file, mtime);
301308
blob_reset(&file);
302309
--- src/unversioned.c
+++ src/unversioned.c
@@ -275,10 +275,11 @@
275 }else{
276 mtime = db_int(0, "SELECT strftime('%%s',%Q)", zMtime);
277 if( mtime<=0 ) fossil_fatal("bad timestamp: %Q", zMtime);
278 }
279 if( memcmp(zCmd, "add", nCmd)==0 ){
 
280 const char *zIn;
281 const char *zAs;
282 Blob file;
283 int i;
284
@@ -287,15 +288,21 @@
287 verify_all_options();
288 db_begin_transaction();
289 content_rcvid_init("#!fossil unversioned add");
290 for(i=3; i<g.argc; i++){
291 zIn = zAs ? zAs : g.argv[i];
292 if( zIn[0]==0 || zIn[0]=='/' || !file_is_simple_pathname(zIn,1) ){
293 fossil_fatal("'%Q' is not an acceptable filename", zIn);
 
 
 
 
 
 
294 }
295 if( contains_whitespace(zIn) ){
296 fossil_fatal("names of unversioned files may not contain whitespace");
297 }
298 blob_init(&file,0,0);
299 blob_read_from_file(&file, g.argv[i]);
300 unversioned_write(zIn, &file, mtime);
301 blob_reset(&file);
302
--- src/unversioned.c
+++ src/unversioned.c
@@ -275,10 +275,11 @@
275 }else{
276 mtime = db_int(0, "SELECT strftime('%%s',%Q)", zMtime);
277 if( mtime<=0 ) fossil_fatal("bad timestamp: %Q", zMtime);
278 }
279 if( memcmp(zCmd, "add", nCmd)==0 ){
280 const char *zError = 0;
281 const char *zIn;
282 const char *zAs;
283 Blob file;
284 int i;
285
@@ -287,15 +288,21 @@
288 verify_all_options();
289 db_begin_transaction();
290 content_rcvid_init("#!fossil unversioned add");
291 for(i=3; i<g.argc; i++){
292 zIn = zAs ? zAs : g.argv[i];
293 if( zIn[0]==0 ){
294 zError = "be empty string";
295 }else if( zIn[0]=='/' ){
296 zError = "be absolute";
297 }else if ( !file_is_simple_pathname(zIn,1) ){
298 zError = "contain complex paths";
299 }else if( contains_whitespace(zIn) ){
300 zError = "contain whitespace";
301 }
302 if( zError ){
303 fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
304 }
305 blob_init(&file,0,0);
306 blob_read_from_file(&file, g.argv[i]);
307 unversioned_write(zIn, &file, mtime);
308 blob_reset(&file);
309

Keyboard Shortcuts

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