<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi,<br>
    <br>
    <blockquote
cite="mid:BF7E5F8590F2D747BEA3963723190596FCA606F3@dedcexch02.seeburger.de"
      type="cite">
      <div class="WordSection1">
        <p class="MsoNormal" style="text-autospace:none"> <br>
          has anyone noticed that the SmbFile.FILE_NO_SHARE option which
          is supposed to grant an exclusive lock on a file, is not
          working anymore?<br>
          I wrote this small example program, which I run under windows
          7 machine.<br>
          The program basically starts 45 threads which try to append
          the text “test\n” in the same file at the same time,
          incrementing a counter if a IOException “File used by another
          process” occurs.<o:p></o:p></p>
        <p class="MsoNormal" style="text-autospace:none"><br>
          At the end, it is expected to have the file text.txt
          containing N rows with the word “test”, and the number 45 – N
          printed in the console (the number of threads that got “File
          used by another process” exception).<br>
          However, the result is different on each execution and never
          correct – the number of rows containing “test” in the test.txt
          file plus the number printed in the console is always smaller
          than 45, which indicates that locking is not working at all.<br>
        </p>
      </div>
    </blockquote>
    Yep, there is a bug - but it's not the locking that is broken, it's
    SmbFileOutputStream's append mode. It does use
    Trans2QueryFSInformationResponse to retrieve the current file length
    as it calls SmbFile.length before opening it (which does not follow
    the sharing semantics and probably has no consistency guarantees
    whatsoever). Therefor your file pointer will be set to a stale
    position and you do not actually append but overwrite already
    present data. Nice.<br>
    <br>
    ( Patch, which may or may not apply cleanly: <a
      class="moz-txt-link-freetext"
href="https://github.com/AgNO3/jcifs-ng/commit/022842a1685293335e918a2a1d5416cf39bccdd9"><a class="moz-txt-link-freetext" href="https://github.com/AgNO3/jcifs-ng/commit/022842a1685293335e918a2a1d5416cf39bccdd9">https://github.com/AgNO3/jcifs-ng/commit/022842a1685293335e918a2a1d5416cf39bccdd9</a></a>
    )<br>
    <br>
    regards<br>
    <br>
    Moritz
  </body>
</html>