Even when I have the versionable 'allow-symlinks' setting on, 'fossil open'
initially creates symlinks as regular files (as if 
.fossil-settings/allow-symlinks did not exist or were set to 'off').

I have to first delete the symlink files and then run 'fossil update'
in order for the setting to take effect and give me proper symlinks.

'TRANSCRIPT - BEFORE' below shows how to see the issue from scratch.

This causes trouble when new developers create sandboxes for the first time, 
especially in large repositories with lots of symlinks.

This is because g.allowSymlinks is false within file.c:symlink_create() 
during the 'fossil open' command.  This in turn is because Fossil doesn't
discover the existence of the file .fossil-settings/allow-symlinks until
after it has cached the false value.

I humbly submit a simple patch (against today's trunk) that I think 
remedies the issue.  'TRANSCRIPT - AFTER' shows the behavior after the 
patch.

PATCH

[miami:src] $ fossil diff
Index: src/vfile.c
==================================================================
--- src/vfile.c
+++ src/vfile.c
@@ -268,21 +268,29 @@
   int promptFlag         /* Prompt user to confirm overwrites */
 ){
   Stmt q;
   Blob content;
   int nRepos = strlen(g.zLocalRoot);
+  char bSawSymlinkSetting = 0;
 
+  /* In order to properly write out symlinks rather than regular files,
+  ** we must first observe the .fossil-settings/allow-symlinks file if it
+  ** exists.  If it does, we want to make sure we see it prior to any
+  ** symlink files.  This is why we sort ascending by 'islink'.
+  */
   if( vid>0 && id==0 ){
     db_prepare(&q, "SELECT id, %Q || pathname, mrid, isexe, islink"
                    "  FROM vfile"
-                   " WHERE vid=%d AND mrid>0",
+                   " WHERE vid=%d AND mrid>0"
+                   " ORDER BY islink ASC",
                    g.zLocalRoot, vid);
   }else{
     assert( vid==0 && id>0 );
     db_prepare(&q, "SELECT id, %Q || pathname, mrid, isexe, islink"
                    "  FROM vfile"
-                   " WHERE id=%d AND mrid>0",
+                   " WHERE id=%d AND mrid>0"
+                   " ORDER BY islink ASC",
                    g.zLocalRoot, id);
   }
   while( db_step(&q)==SQLITE_ROW ){
     int id, rid, isExe, isLink;
     const char *zName;
@@ -291,10 +299,21 @@
     zName = db_column_text(&q, 1);
     rid = db_column_int(&q, 2);
     isExe = db_column_int(&q, 3);
     isLink = db_column_int(&q, 4);
     content_get(rid, &content);
+    if( !bSawSymlinkSetting &&
+        zName[nRepos]=='.' && zName[nRepos+1]=='f' && zName[nRepos+2]=='o' &&
+        strcmp(&zName[nRepos], ".fossil-settings/allow-symlinks")==0
+    ){
+      bSawSymlinkSetting = 1;
+      char zValue[4] = {0,0,0,0};
+      int i;
+      snprintf(zValue, sizeof(zValue), "%s", blob_str(&content));
+      for (i=3;i>=1;--i) {if (zValue[i]=='\n') {zValue[i]=0; break;}}
+      g.allowSymlinks = is_truth(zValue);
+    }
     if( file_is_the_same(&content, zName) ){
       blob_reset(&content);
       if( file_wd_setexe(zName, isExe) ){
         db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
                       file_wd_mtime(zName), id);

TRANSCRIPT - BEFORE

[miami:fstest] $ fossil new
Usage: fossil new REPOSITORY-NAME
[miami:fstest] $ fossil new test
project-id: 981a44330154ce354fc1407af51b2ccaaacf1440
server-id:  71ac17e7234eee4a388e3c8321ce5bc8e698e966
admin-user: eas (initial password is "72f66b")
[miami:fstest] $ mkdir sandbox1
[miami:fstest] $ cd !$
cd sandbox1
[miami:sandbox1] $ fossil open ../test
project-name: <unnamed>
repository:   /home/eas/tmp/fstest/sandbox1/../test
local-root:   /home/eas/tmp/fstest/sandbox1/
config-db:    /home/eas/.fossil
project-code: 981a44330154ce354fc1407af51b2ccaaacf1440
checkout:     c8b4245419520d30cc360295cfa22d28c814e586 2014-10-31 00:24:42 UTC
leaf:         open
tags:         trunk
comment:      initial empty check-in (user: eas)
checkins:     1
[miami:sandbox1] $ >a
[miami:sandbox1] $ ln -s a b
[miami:sandbox1] $ ls
a  b@
[miami:sandbox2] $ ls -l
total 0
-rw-r--r--. 1 eas eas 0 Oct 30 20:25 a
lrwxrwxrwx. 1 eas eas 1 Oct 30 20:26 b -> a
[miami:sandbox1] $ mkdir .fossil-settings
[miami:sandbox1] $ echo on > .fossil-settings/allow-symlinks
[miami:sandbox1] $ fossil add .fossil-settings/allow-symlinks a b
ADDED  .fossil-settings/allow-symlinks
ADDED  a
ADDED  b
[miami:sandbox1] $ fossil commit -m Test
New_Version: 3aee795224e735d8b6c08f3bcd10c8acf98b15c0
[miami:sandbox1] $ cd ..
[miami:fstest] $ mkdir sandbox2
[miami:fstest] $ cd sandbox2
[miami:sandbox2] $ fossil open ../test 
.fossil-settings/allow-symlinks
a
b
project-name: <unnamed>
repository:   /home/eas/tmp/fstest/sandbox2/../test
local-root:   /home/eas/tmp/fstest/sandbox2/
config-db:    /home/eas/.fossil
project-code: 981a44330154ce354fc1407af51b2ccaaacf1440
checkout:     3aee795224e735d8b6c08f3bcd10c8acf98b15c0 2014-10-31 00:25:31 UTC
parent:       c8b4245419520d30cc360295cfa22d28c814e586 2014-10-31 00:24:42 UTC
leaf:         open
tags:         trunk
comment:      Test (user: eas)
checkins:     2
[miami:sandbox2] $ ls -l
total 4
-rw-r--r--. 1 eas eas 0 Oct 30 20:25 a
-rw-r--r--. 1 eas eas 1 Oct 30 20:25 b
[miami:sandbox2] $ cat b
a[miami:sandbox2] $ rm b
rm: remove regular file `b'? y
[miami:sandbox2] $ fossil update
UPDATE b
-------------------------------------------------------------------------------
updated-to:   3aee795224e735d8b6c08f3bcd10c8acf98b15c0 2014-10-31 00:25:31 UTC
leaf:         open
tags:         trunk
comment:      Test (user: eas)
changes:      1 file modified.
 "fossil undo" is available to undo changes to the working checkout.
[miami:sandbox2] $ ls -l
total 0
-rw-r--r--. 1 eas eas 0 Oct 30 20:25 a
lrwxrwxrwx. 1 eas eas 1 Oct 30 20:26 b -> a

TRANSCRIPT - AFTER

[miami:fstest] $ mkdir sandbox3
[miami:fstest] $ cd !$
cd sandbox3
[miami:sandbox3] $ ~/fossil-scm/bld/fossil open ../test
.fossil-settings/allow-symlinks
a
b
project-name: <unnamed>
repository:   /home/eas/tmp/fstest/sandbox3/../test
local-root:   /home/eas/tmp/fstest/sandbox3/
config-db:    /home/eas/.fossil
project-code: 981a44330154ce354fc1407af51b2ccaaacf1440
checkout:     3aee795224e735d8b6c08f3bcd10c8acf98b15c0 2014-10-31 00:25:31 UTC
parent:       c8b4245419520d30cc360295cfa22d28c814e586 2014-10-31 00:24:42 UTC
leaf:         open
tags:         trunk
comment:      Test (user: eas)
checkins:     2
[miami:sandbox3] $ ls -l
total 0
-rw-r--r--. 1 eas eas 0 Oct 30 21:26 a
lrwxrwxrwx. 1 eas eas 1 Oct 30 21:26 b -> a

--
Eric A. Rubin-Smith

Aterlo Networks, Inc.
http://aterlo.com

_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to