Fossil SCM

Make sure that symlinks to directories are honored when dealing with checkout files.

mistachkin 2016-10-04 04:49 UTC trunk merge
Commit 912a0d500884dff12593880b7f76b1283c2e14ee
+1 -1
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -922,11 +922,11 @@
922922
if( pFileDir ){
923923
int i;
924924
for(i=0; pFileDir[i].zName; i++){
925925
if( pFileDir[i].nUsed==0
926926
&& strcmp(pFileDir[0].zName,".")!=0
927
- && !file_isdir(g.argv[i+2])
927
+ && !file_wd_isdir(g.argv[i+2])
928928
){
929929
fossil_fatal("not found: '%s'", g.argv[i+2]);
930930
}
931931
fossil_free(pFileDir[i].zName);
932932
}
933933
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -922,11 +922,11 @@
922 if( pFileDir ){
923 int i;
924 for(i=0; pFileDir[i].zName; i++){
925 if( pFileDir[i].nUsed==0
926 && strcmp(pFileDir[0].zName,".")!=0
927 && !file_isdir(g.argv[i+2])
928 ){
929 fossil_fatal("not found: '%s'", g.argv[i+2]);
930 }
931 fossil_free(pFileDir[i].zName);
932 }
933
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -922,11 +922,11 @@
922 if( pFileDir ){
923 int i;
924 for(i=0; pFileDir[i].zName; i++){
925 if( pFileDir[i].nUsed==0
926 && strcmp(pFileDir[0].zName,".")!=0
927 && !file_wd_isdir(g.argv[i+2])
928 ){
929 fossil_fatal("not found: '%s'", g.argv[i+2]);
930 }
931 fossil_free(pFileDir[i].zName);
932 }
933
+21 -9
--- src/file.c
+++ src/file.c
@@ -293,24 +293,36 @@
293293
}
294294
return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
295295
}
296296
297297
/*
298
-** Same as file_isdir(), but takes into account symlinks.
298
+** Same as file_isdir(), but takes into account symlinks. Return 1 if
299
+** zFilename is a directory -OR- a symlink that points to a directory.
300
+** Return 0 if zFilename does not exist. Return 2 if zFilename exists
301
+** but is something other than a directory.
299302
*/
300303
int file_wd_isdir(const char *zFilename){
301304
int rc;
305
+ char *zFN;
302306
303
- if( zFilename ){
304
- char *zFN = mprintf("%s", zFilename);
305
- file_simplify_name(zFN, -1, 0);
306
- rc = getStat(zFN, 1);
307
- free(zFN);
307
+ zFN = mprintf("%s", zFilename);
308
+ file_simplify_name(zFN, -1, 0);
309
+ rc = getStat(zFN, 1);
310
+ if( rc ){
311
+ rc = 0; /* It does not exist at all. */
312
+ }else if( S_ISDIR(fileStat.st_mode) ){
313
+ rc = 1; /* It exists and is a real directory. */
314
+ }else if( S_ISLNK(fileStat.st_mode) ){
315
+ Blob content;
316
+ blob_read_link(&content, zFN); /* It exists and is a link. */
317
+ rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */
318
+ blob_reset(&content);
308319
}else{
309
- rc = getStat(0, 1);
320
+ rc = 2; /* It exists and is something else. */
310321
}
311
- return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
322
+ free(zFN);
323
+ return rc;
312324
}
313325
314326
315327
/*
316328
** Wrapper around the access() system call.
@@ -600,11 +612,11 @@
600612
** The if stops us from trying to create a directory of a drive letter
601613
** C: in this example.
602614
*/
603615
if( !(i==2 && zName[1]==':') ){
604616
#endif
605
- if( file_mkdir(zName, forceFlag) && file_isdir(zName)!=1 ){
617
+ if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){
606618
if (errorReturn <= 0) {
607619
fossil_fatal_recursive("unable to create directory %s", zName);
608620
}
609621
rc = errorReturn;
610622
break;
611623
612624
ADDED test/symlinks.test
--- src/file.c
+++ src/file.c
@@ -293,24 +293,36 @@
293 }
294 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
295 }
296
297 /*
298 ** Same as file_isdir(), but takes into account symlinks.
 
 
 
299 */
300 int file_wd_isdir(const char *zFilename){
301 int rc;
 
302
303 if( zFilename ){
304 char *zFN = mprintf("%s", zFilename);
305 file_simplify_name(zFN, -1, 0);
306 rc = getStat(zFN, 1);
307 free(zFN);
 
 
 
 
 
 
 
308 }else{
309 rc = getStat(0, 1);
310 }
311 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
 
312 }
313
314
315 /*
316 ** Wrapper around the access() system call.
@@ -600,11 +612,11 @@
600 ** The if stops us from trying to create a directory of a drive letter
601 ** C: in this example.
602 */
603 if( !(i==2 && zName[1]==':') ){
604 #endif
605 if( file_mkdir(zName, forceFlag) && file_isdir(zName)!=1 ){
606 if (errorReturn <= 0) {
607 fossil_fatal_recursive("unable to create directory %s", zName);
608 }
609 rc = errorReturn;
610 break;
611
612 DDED test/symlinks.test
--- src/file.c
+++ src/file.c
@@ -293,24 +293,36 @@
293 }
294 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
295 }
296
297 /*
298 ** Same as file_isdir(), but takes into account symlinks. Return 1 if
299 ** zFilename is a directory -OR- a symlink that points to a directory.
300 ** Return 0 if zFilename does not exist. Return 2 if zFilename exists
301 ** but is something other than a directory.
302 */
303 int file_wd_isdir(const char *zFilename){
304 int rc;
305 char *zFN;
306
307 zFN = mprintf("%s", zFilename);
308 file_simplify_name(zFN, -1, 0);
309 rc = getStat(zFN, 1);
310 if( rc ){
311 rc = 0; /* It does not exist at all. */
312 }else if( S_ISDIR(fileStat.st_mode) ){
313 rc = 1; /* It exists and is a real directory. */
314 }else if( S_ISLNK(fileStat.st_mode) ){
315 Blob content;
316 blob_read_link(&content, zFN); /* It exists and is a link. */
317 rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */
318 blob_reset(&content);
319 }else{
320 rc = 2; /* It exists and is something else. */
321 }
322 free(zFN);
323 return rc;
324 }
325
326
327 /*
328 ** Wrapper around the access() system call.
@@ -600,11 +612,11 @@
612 ** The if stops us from trying to create a directory of a drive letter
613 ** C: in this example.
614 */
615 if( !(i==2 && zName[1]==':') ){
616 #endif
617 if( file_mkdir(zName, forceFlag) && file_wd_isdir(zName)!=1 ){
618 if (errorReturn <= 0) {
619 fossil_fatal_recursive("unable to create directory %s", zName);
620 }
621 rc = errorReturn;
622 break;
623
624 DDED test/symlinks.test
--- a/test/symlinks.test
+++ b/test/symlinks.test
@@ -0,0 +1,65 @@
1
+#
2
+# Copyright (c) 2016 D. Richard Hipp
3
+#
4
+# This program is free software; you can redistribute it and/or
5
+# modify it under the terms of the Simplified BSD License (also
6
+# known as the "2-Clause License" or "FreeBSD License".)
7
+#
8
+# This program is distributed in the hope that it will be useful,
9
+# but without any warranty; without even the implied warranty of
10
+# merchantability or fitness for a particular purpose.
11
+#
12
+# Author contact information:
13
+# [email protected]
14
+# http://www.hwaci.com/drh/
15
+#
16
+############################################################################
17
+#
18
+# Symbolic link tests.
19
+#
20
+
21
+if {$tcl_platform(platform) eq "windows"allow
22
+puts $RESULTmlinks are test_cleanup_then_return
23
+}
24
+
25
+require_no_open_checkoupen-config {repository}
26
+set reposi"setting allow-symlinks"
27
+
28
+i {[string length $repository] == 0} {
29
+ putssymlinks-repository \
30
+ test_cleanup_then_return
31
+ht (c) 2016 D. #
32
+# Copyright (c) 2016 D. Richard Hipp
33
+#
34
+# This program is free software; you can redistribute it and/or
35
+# modify it under the terms of fossil commit -m "c1"open_checkoupen-config {repository}
36
+set reposi"setting allow-symlinks"
37
+
38
+i {[string length ght (c) 2016 D. Rich#
39
+# Copyright o_open_checkoupen-config {repository}
40
+set reposi"setting allow-symlinks"
41
+
42
+i {[string length $repository] == 0} {
43
+ putssymlinks-repository \
44
+ test_cleanup_then_return
45
+ht (c) 2016 D. #
46
+# Copyright (c) 2016 D. Richard Hipp
47
+#
48
+# This program is free software; you can redistribute it and/or
49
+# modify it under the terms of the Simplified BSD License (also
50
+# known as the "2-Clause License" or "FreeBSD License".)
51
+#
52
+# This program is distributed in the hope that it will be useful,
53
+# but without any warranty; without even the implied warranty of
54
+# merchantability or fitness for a particular purpose.
55
+#
56
+# Author contact information:
57
+# [email protected]
58
+# http://www.hwaci.com/drh/
59
+#
60
+############################################################################
61
+#
62
+# Symbolic link tests.
63
+#
64
+
65
+set pat
--- a/test/symlinks.test
+++ b/test/symlinks.test
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/symlinks.test
+++ b/test/symlinks.test
@@ -0,0 +1,65 @@
1 #
2 # Copyright (c) 2016 D. Richard Hipp
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the Simplified BSD License (also
6 # known as the "2-Clause License" or "FreeBSD License".)
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but without any warranty; without even the implied warranty of
10 # merchantability or fitness for a particular purpose.
11 #
12 # Author contact information:
13 # [email protected]
14 # http://www.hwaci.com/drh/
15 #
16 ############################################################################
17 #
18 # Symbolic link tests.
19 #
20
21 if {$tcl_platform(platform) eq "windows"allow
22 puts $RESULTmlinks are test_cleanup_then_return
23 }
24
25 require_no_open_checkoupen-config {repository}
26 set reposi"setting allow-symlinks"
27
28 i {[string length $repository] == 0} {
29 putssymlinks-repository \
30 test_cleanup_then_return
31 ht (c) 2016 D. #
32 # Copyright (c) 2016 D. Richard Hipp
33 #
34 # This program is free software; you can redistribute it and/or
35 # modify it under the terms of fossil commit -m "c1"open_checkoupen-config {repository}
36 set reposi"setting allow-symlinks"
37
38 i {[string length ght (c) 2016 D. Rich#
39 # Copyright o_open_checkoupen-config {repository}
40 set reposi"setting allow-symlinks"
41
42 i {[string length $repository] == 0} {
43 putssymlinks-repository \
44 test_cleanup_then_return
45 ht (c) 2016 D. #
46 # Copyright (c) 2016 D. Richard Hipp
47 #
48 # This program is free software; you can redistribute it and/or
49 # modify it under the terms of the Simplified BSD License (also
50 # known as the "2-Clause License" or "FreeBSD License".)
51 #
52 # This program is distributed in the hope that it will be useful,
53 # but without any warranty; without even the implied warranty of
54 # merchantability or fitness for a particular purpose.
55 #
56 # Author contact information:
57 # [email protected]
58 # http://www.hwaci.com/drh/
59 #
60 ############################################################################
61 #
62 # Symbolic link tests.
63 #
64
65 set pat

Keyboard Shortcuts

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