hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

[Question] File locking #553

Open alb-i986 opened 4 years ago

alb-i986 commented 4 years ago

Hi,

Quick question: do you support file locking by any chance? I tried to search in the repo for files named "lock" but I couldn't find any.

I need to read/write a file on a share and I need to handle concurrent accesses from different processes, so what I need I think is a file locking mechanism on the smb library side.

I'll appreciate any help, Thanks

Flemoz commented 4 years ago

When you open a file, you can specify the set of SMB2ShareAccess values that defines what accesses other processes have when the file is already opened. Empty set means the current process has exclusive access. I think this is what you are looking for.

alb-i986 commented 4 years ago

Yeah, I think so too. I was doing some research and I just found that. Thanks, I'll give it a try.

alb-i986 commented 4 years ago

One thing: maybe a constant specifically with that purpose would help, rather than passing null, which is not good practice. Because I see that in the constructor of SMB2CreateRequest, if shareAccesses is null, it is set to EnumSet.noneOf

I was looking at JCIFS and they have the constant FILE_NO_SHARE

Here, since we have SMB2ShareAccess.ALL, it would make sense to have an enum constant SMB2ShareAccess.NONE.