MINA SSHD
  1. MINA SSHD
  2. SSHD-97

Uploading file via SFTP leaves file in locked state on Windows

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.5.0
    • Fix Version/s: 0.6.0
    • Labels:
      None
    • Environment:
      JDK 1.6.0_18 (32bit) running on Win 7 (64 bit). I've a fairly out-of-the-box Mina SSHD / sftp config. I'm serving from my local Windows machine.

      Description

      Uploading a file via SFTP leaves the file in a locked state. Specifically, when I upload a file using sftpd, the file is locked in windows, even after the upload is complete.

      I verified this by using Yourkit Profiler (see attached screenshots). There are two writes to the file

      • first: NativeSshFile.truncate() erases the old file. This is what fails to clean up
      • second: NativeSshFile.createOutputStream(). This is properly closed after use.

      The fix is simple. In the truncate() method, close the RandomAccessFile after it is created. See attached patch.

      I tested this by putting the truncate method in a subclass of NativeSshFile and it solved the problem.

      After applying the patch to the Mina SSHD source code, I ran "mvn test" which passed.

      1. patch.txt
        1 kB
        Will Glass-Husain
      2. notclosed.png
        107 kB
        Will Glass-Husain
      3. stacktrace.png
        132 kB
        Will Glass-Husain

        Activity

        Will Glass-Husain created issue -
        Will Glass-Husain made changes -
        Field Original Value New Value
        Attachment patch.txt [ 12460088 ]
        Will Glass-Husain made changes -
        Attachment notclosed.png [ 12460089 ]
        Attachment stacktrace.png [ 12460090 ]
        Hide
        Will Glass-Husain added a comment -

        As a side note, before this patch is applied "mvn test" fails on Windows. (i.e. sftpTest tries to delete a file but can't). After this patch is applied the tests pass.

        Show
        Will Glass-Husain added a comment - As a side note, before this patch is applied "mvn test" fails on Windows. (i.e. sftpTest tries to delete a file but can't). After this patch is applied the tests pass.
        Hide
        Guillaume Nodet added a comment -

        Thxnk a ton for the patch!

        Committing to https://svn.apache.org/repos/asf/mina/sshd/trunk ...
        M sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java
        Committed r1039429

        Show
        Guillaume Nodet added a comment - Thxnk a ton for the patch! Committing to https://svn.apache.org/repos/asf/mina/sshd/trunk ... M sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java Committed r1039429
        Guillaume Nodet made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Guillaume Nodet [ gnt ]
        Fix Version/s 0.6.0 [ 12315514 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        6d 11h 35m 1 Guillaume Nodet 26/Nov/10 16:00

          People

          • Assignee:
            Guillaume Nodet
            Reporter:
            Will Glass-Husain
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development