[jcifs] Getting concurrency error when deleting a file

Michael B Allen ioplex at gmail.com
Tue Mar 3 16:15:18 GMT 2009


On Tue, Mar 3, 2009 at 4:50 AM, Hugo Palma <hugo.m.palma at gmail.com> wrote:
> Thanks for the tip. Got me thinking about the permissions and i solved it by
> changing my code to:
>
> SmbFile folder = new SmbFile("smb://myfolder");
> for (String filePath : folder.list()) {
>      SmbFile file = new SmbFile(folder.getPath() + filePath, null,
> SmbFile.FILE_SHARE_DELETE);
>
>      // do something
>
>     file.delete();
>   }

This does not make sense. The default shareAccess value is
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE which means
other clients should be premitted to perform all of those operations.

Did you previously supply a shareAccess parameter value of 0 by accident?

If not, I will have to spend time investigating this issue.

Mike

>
> On Tue, Mar 3, 2009 at 1:52 AM, Michael B Allen <ioplex at gmail.com> wrote:
>>
>> On Mon, Mar 2, 2009 at 1:46 PM, Hugo Palma <hugo.m.palma at gmail.com> wrote:
>> > Hi all,
>> > a have a very simple use case where i want to get all the file in a
>> > directory, iterate over them a delete a few.
>> > My code is something like:
>> >
>> > SmbFile folder = new SmbFile("smb://myfolder");
>> > for (SmbFile file : folder.listFiles()) {
>> >     // do something
>> >
>> >    file.delete();
>> > }
>> >
>> > It seems that if that "do something" doesn't include calling the
>> > "getInputStream" method on the file everything goes fine. But if it does
>> > i
>> > get the following error on the delete operation:
>>
>> I would think that that should still work since I thought
>> getInputStream opened the file with a permissible shareAccess. Perhaps
>> not.
>>
>> Anyway, try calling close() on the InputStream before you delete().
>>
>> Mike
>> - Show quoted text -
>> >
>> > jcifs.smb.SmbException: The process cannot access the file because it is
>> > being used by another process.
>> >         at
>> > jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:522)
>> >         at
>> > jcifs.smb.SmbTransport.send(SmbTransport.java:622)
>> >         at
>> > jcifs.smb.SmbSession.send(SmbSession.java:239)
>> >         at
>> > jcifs.smb.SmbTree.send(SmbTree.java:109)
>> >         at
>> > jcifs.smb.SmbFile.send(SmbFile.java:718)
>> >         at
>> > jcifs.smb.SmbFile.delete(SmbFile.java:2342)
>> >         at jcifs.smb.SmbFile.delete(SmbFile.java:2286)
>> >
>> >
>> > Any idea why this is happening ? Clearly some resource if being left
>> > open
>> > but i don't see any close method.
>> > Thanks
>> >
>>
>>
>>
>> --
>> Michael B Allen
>> Java Active Directory Integration
>> http://www.ioplex.com/
>
>
>



-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/


More information about the jcifs mailing list