Re: [fossil-users] proposed patch: symlinks appear as regular files even when allow-symlinks is on

2014-10-31 Thread Stephan Beal
On Fri, Oct 31, 2014 at 8:17 AM, Stephan Beal sgb...@googlemail.com wrote:

 +  char zValue[4] = {0,0,0,0};
 +  int i;
 +  snprintf(zValue, sizeof(zValue), %s, blob_str(content));


 Minor nitpick: snprintf() is not c89. i would recommend using another blob
 for zValue, and blob_appendf().


Or, since we only care if zValue is on or off, expand the if() around that
and set zValue to either on or off directly, as opposed to copying the
value from content.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do. -- Bigby Wolf
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] proposed patch: symlinks appear as regular files even when allow-symlinks is on

2014-10-31 Thread Matt Welland
Since you all are looking at symlinks someone reported to me that there are
problems when a symlink is replaced with a directory or vice versa. Here is
the script that he generated to illustrate the issue:

## Create repo and initial population

fossil init bare.repo

mkdir link_target_dir
touch link_target_file
mkdir work1
cd work1
fossil open ../bare.repo
touch file
mkdir dir1
touch dir1/file1
ln -s ../link_target_file .
ln -s ../link_target_dir .
fossil add *
fossil commit -m add initial files .

## Clone repo
cd ..
mkdir work2
cd work2
fossil open ../bare.repo

## Change file types in repo
cd ../work1
echo Removing targets
fossil rm  dir1 file link_target_dir link_target_file
fossil commit -m remove all .
chmod -R 700 dir1 file link_target_dir link_target_file
rm -rf dir1 file link_target_dir link_target_file
echo Creating new targets swapping types
ln -s ../link_target_dir dir1
ln -s ../link_target_file file
mkdir link_target_dir
touch link_target_file
touch link_target_dir/file2
echo Adding to fossil
fossil add *
echo Commiting
fossil commit -m switch all types .

## Attempt pull in clone
cd ../work2

## At this command Fossil fails because it cannot swap the directory dir1
for the link that was created in it's place
fossil update
exit


On Fri, Oct 31, 2014 at 3:11 AM, Richard Hipp d...@sqlite.org wrote:



 On Fri, Oct 31, 2014 at 3:17 AM, Stephan Beal sgb...@googlemail.com
 wrote:


 +  char zValue[4] = {0,0,0,0};
 +  int i;
 +  snprintf(zValue, sizeof(zValue), %s, blob_str(content));


 Minor nitpick: snprintf() is not c89. i would recommend using another
 blob for zValue, and blob_appendf().


 sqlite3_snprintf() is guaranteed to be available.  Note, though, that the
 first two parameters are reversed.  :-\
 --
 D. Richard Hipp
 d...@sqlite.org

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




-- 
Matt
-=-
90% of the nations wealth is held by 2% of the people. Bummer to be in the
majority...
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] proposed patch: symlinks appear as regular files even when allow-symlinks is on

2014-10-31 Thread Eric Rubin-Smith
Richard Hipp wrote:

 sqlite3_snprintf() is guaranteed to be available.  Note, though, that the
 first two parameters are reversed.  :-\

Well, I only really want to copy up to 3 bytes, so we can keep it
simple, stupid and just not make a function call.  The revised patch is
below.  

But in further testing, I noticed that there is a series of
fossil calls involving a sequence of on/off settings to allow-symlinks
intermixed with 'fossil update', 'rm', etc that would result in fossil 
starting to return errors on 'update'.  I'm not convinced yet that it 
is a regression, but the below should be treated with caution until I've 
had a chance to look at it further.

I probably won't get back to that for at least 10 days, though.  Someone 
else can feel free to pick it up from here if they would like.

To Stephan's earlier point about just looking specifically for on and
off: I would prefer not to do that, since it duplicates logic from 
is_truth().  (Maybe the fossil devs will want to allow y in the
future or something, and I wouldn't want a little gotcha lurking in the
present patch when that happens.  And in any case just looking for yes
would skip the present valid values of 1, on, and true.)

[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( vid0  id==0 ){
 db_prepare(q, SELECT id, %Q || pathname, mrid, isexe, islink
  FROM vfile
-WHERE vid=%d AND mrid0,
+WHERE vid=%d AND mrid0
+ORDER BY islink ASC,
g.zLocalRoot, vid);
   }else{
 assert( vid==0  id0 );
 db_prepare(q, SELECT id, %Q || pathname, mrid, isexe, islink
  FROM vfile
-WHERE id=%d AND mrid0,
+WHERE id=%d AND mrid0
+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
+){
+  char zValue[4] = {0,0,0,0};
+  int i=0;
+  bSawSymlinkSetting = 1;
+  const char* zCont = blob_str(content);
+  while( i3  zCont[i]!=0  zCont[i]!='\n' ){zValue[i]=zCont[i]; ++i;}
+  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);


--
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


Re: [fossil-users] proposed patch: symlinks appear as regular files even when allow-symlinks is on

2014-10-31 Thread Eric Rubin-Smith
Another iteration.  We need to add an extra byte in case the true
value is the string true.  I've re-expressed the loop as a 'for' loop
while I was at it.

Sorry for the spam.  Again, please treat the below with caution until 
I have (or someone else has) a chance to exercise it better.

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( vid0  id==0 ){
 db_prepare(q, SELECT id, %Q || pathname, mrid, isexe, islink
  FROM vfile
-WHERE vid=%d AND mrid0,
+WHERE vid=%d AND mrid0
+ORDER BY islink ASC,
g.zLocalRoot, vid);
   }else{
 assert( vid==0  id0 );
 db_prepare(q, SELECT id, %Q || pathname, mrid, isexe, islink
  FROM vfile
-WHERE id=%d AND mrid0,
+WHERE id=%d AND mrid0
+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
+){
+  char zValue[5] = {0,0,0,0,0};
+  int i;
+  bSawSymlinkSetting = 1;
+  const char* zCont = blob_str(content);
+  for(i=0; i4  zCont[i]!=0  zCont[i]!='\n';++i ){ zValue[i]=zCont[i]; 
}
+  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);


--
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


[fossil-users] proposed patch: symlinks appear as regular files even when allow-symlinks is on

2014-10-30 Thread Eric Rubin-Smith
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( vid0  id==0 ){
 db_prepare(q, SELECT id, %Q || pathname, mrid, isexe, islink
  FROM vfile
-WHERE vid=%d AND mrid0,
+WHERE vid=%d AND mrid0
+ORDER BY islink ASC,
g.zLocalRoot, vid);
   }else{
 assert( vid==0  id0 );
 db_prepare(q, SELECT id, %Q || pathname, mrid, isexe, islink
  FROM vfile
-WHERE id=%d AND mrid0,
+WHERE id=%d AND mrid0
+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:  

Re: [fossil-users] proposed patch: symlinks appear as regular files even when allow-symlinks is on

2014-10-30 Thread David Mason
Excellent!  I reported on the bug here some time ago, but didn't
provide a fix.  I hope this gets into trunk soon.

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