[jcifs] Trouble deleting directory-- receive error message "The process cannot access the file because it is being used by another process."

Brian Bernstein brian.bernstein at indorse-tech.com
Mon Dec 3 17:01:30 GMT 2007


I am having trouble deleting a directory with contents within it
shortly after creating said directory.

Here's what I do to receive this error:
First, I create a directory on a resource, with full share permissions.
SmbFile file = new SmbFile(dirUrl, credentials,
SmbFile.FILE_SHARE_READ|SmbFile.FILE_SHARE_WRITE|SmbFile.FILE_SHARE_DELETE);
file.mkDir();

Then I place files within this directory.
SmbFile file = new SmbFile(dirUrl/fileName, credentials,
SmbFile.FILE_SHARE_READ|SmbFile.FILE_SHARE_WRITE|SmbFile.FILE_SHARE_DELETE);
file.getOutputStream.write(fileContents);

(this step can be repeated a few times).

Lastly, I try to delete the directory, however the original SmbFile
reference has since been lost, so a new connection is made.
SmbFile file = new SmbFile(dirUrl, credentials,
SmbFile.FILE_SHARE_READ|SmbFile.FILE_SHARE_WRITE|SmbFile.FILE_SHARE_DELETE);
file.delete();

However, the deletion fails and instead I get this exception:
jcifs.smb.SmbException: The process cannot access the file because it
is being used by another process.
 	at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:514)
 	at jcifs.smb.SmbTransport.send(SmbTransport.java:614)
 	at jcifs.smb.SmbSession.send(SmbSession.java:239)
 	at jcifs.smb.SmbTree.send(SmbTree.java:109)
 	at jcifs.smb.SmbFile.send(SmbFile.java:695)
 	at jcifs.smb.SmbFile.delete(SmbFile.java:2380)
 	at jcifs.smb.SmbFile.delete(SmbFile.java:2324)
 	at jcifs.smb.SmbFile.delete(SmbFile.java:2366)
 	at jcifs.smb.SmbFile.delete(SmbFile.java:2324)

First off, I was under the impression that if I open these resources
with full share permissions
(FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE) that I would not
be having these issues (isn't that what the FILE_SHARE_DELETE
permissions is for?).  Do these permissions not apply towards
directories or do not work when recursing?

I believe this issue is a timeout issue.  If the original socket(s)
are allowed to timeout before the attempt is made, the delete works
without an issue, however this timeout appears to be on the magnitude
of minutes, which is too long.

I had attempted to override this with the setConnectTimeout() but
found it quite difficult to find an appropriate value to set this to
as setting it too low would cause problems when trying to write to the
connection.

Is there a way to perform an explicit disconnect when done with the connection?

Any assistance with this would be greatly appreciated.

-Brian
-- 
======================================
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2


More information about the jcifs mailing list