<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-text-html" lang="x-western">Dear all, <br>
      <br>
      we found a small issue in the function that creates/checks
      directories, that makes QE stop with an error if the scratch
      directory is a symlink.<br>
      <br>
      In particular, in clib/c_mkdir.c, in the check_writable_dir
      function, it is written:<br>
      <br>
      <tt>#if defined(_WIN32)</tt><tt><br>
      </tt><tt>    /* windows has no symlinks so we use stat(2) */</tt><tt><br>
      </tt><tt>    if (stat(filename, &sb) == -1) {</tt><tt><br>
      </tt><tt>      return -3; /* does not exist */</tt><tt><br>
      </tt><tt>      /* note: this happens also if looking for "dir/"
        when there is a file cal\</tt><tt><br>
      </tt><tt>led "dir" */</tt><tt><br>
      </tt><tt>    }</tt><tt><br>
      </tt><tt>#else</tt><tt><br>
      </tt><tt><b>    /* lstat follows symlinks */</b></tt><tt><b><br>
        </b></tt><tt><b>    if (lstat(filename, &sb) == -1) {</b></tt><tt><b><br>
        </b></tt><tt>      return -3; /* does not exist */</tt><tt><br>
      </tt><tt>      /* note: this happens also if looking for "dir/"
        when there is a file cal\</tt><tt><br>
      </tt><tt>led "dir" */</tt><tt><br>
      </tt><tt>    }</tt><tt><br>
      </tt><tt>#endif</tt><tt><br>
      </tt><br>
      However, 'man lstat' states the opposite, that is, 'stat' follows
      symlinks and 'lstat' does not:<br>
      <br>
      <tt>lstat() is identical to stat(), except that if path is a
        symbolic link, then the link itself is stat-ed, not the  file
        that it refers to.</tt><tt><br>
      </tt><br>
      Indeed, in the current version of QE, if the PREFIX.save folder is
      a symlink, at the end the calculation crashes with a "unable to
      create directory" error because the check_writable_dir routine is
      checking the symlink and not the linked folder.<br>
      <br>
      Changing lstat with stat, everything seems to work properly,
      instead (moreover, probably the <tt>#if defined(_WIN32)</tt>
      could also be removed, because the two sections would become
      identical).<br>
      <br>
      Does anyone have expertise with these functions and give us
      feedback on whether our modification makes sense and does not
      create different problems, and if we can proceed to commit the
      change?<br>
      <br>
      Thanks,<br>
      <br>
      Andrea Cepellotti and Giovanni Pizzi, THEOS-EPFL, Switzerland<br>
      <br>
      <br>
    </div>
  </body>
</html>