Hi,

I'm testing version 3100000.

and I'm quite sure that commit:

On unix, if a file is opened via a symlink, create, read and write 
journal and wal files based on the name of the actual db file, not the 
symlink.

introduce a bug in the following condition:
1. create a realive symlink
2. use sqlite with current working dir different from where the symlink 
is created.

the problem came from that the relative path is converted to absolute 
path using the current working directory. But this is not corrected if 
the original file is a symbolc link. For a symlink relative means 
relative from the position of symlink.

I'm testing the following patch that seams to fix the issue.
Regards
Michele Dionisio

diff --git a/src/os_unix.c b/src/os_unix.c
index ee9b556..cfd904e 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -5927,6 +5927,28 @@ static int unixAccess(
    return SQLITE_OK;
  }

+/*
+** Turn an offset inside the given path to the last end of the last
+** directory name
+**
+** return in valid only if bigger than 0
+*/
+static int dirnameLastChrPos(
+    const char *path
+){
+  const char *last_slash = strrchr (path, '/');
+
+  if (last_slash != NULL) {
+      for (; last_slash != path; --last_slash) {
+          if (last_slash[-1] != '/') {
+            break;
+          }
+      }
+      return (last_slash - path);
+  }
+
+  return -1;
+}

  /*
  ** Turn a relative pathname into a full pathname. The relative path
@@ -5970,6 +5992,15 @@ static int unixFullPathname(
      nByte = sqlite3Strlen30(zOut);
    }else{
      zOut[nByte] = '\0';
+    if( zOut[0]!='/' && zPath[0]=='/' ) {  // if symlink is not 
relative and original file name in not relative
+        int nDir = dirnameLastChrPos(zPath);
+        if (nDir>0 && (nDir+nByte+1)<nOut) {
+            memmove(&zOut[nDir + 1], zOut, nByte+1);
+            memcpy(zOut, zPath, nDir);
+            zOut[nDir] = '/';
+            nByte += nDir + 1;
+        }
+    }
    }
  #endif


-- 

Powersoft logo <http://www.powersoft.it>

*Michele Dionisio |*Embedded System Manager

*skype:*  m.dionisio *| email:* michele.dionisio at powersoft.it 
<mailto:marco.cati at powersoft.it>

*HQ Italy:* Via E. Conti, 5 *|* 50018 Scandicci (FI) Italy

*direct phone:*  +39 055 735 0230 *| Fax:*   +39 055 735 6235

*web site:* www.powersoft.it

Green Audio Power

Reply via email to