Skip to content

Commit

Permalink
Updating due to review commentary.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Niggemann committed Dec 13, 2016
1 parent bd62ccd commit 53970ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 46 deletions.
8 changes: 4 additions & 4 deletions src/it/java/SmbjTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ public void testRpc() throws IOException, SMBApiException, URISyntaxException {
System.out.println(ace.getSid() + "-" + ace.getAceHeader());
sids.add(ace.getSid());
}
ShareInfo info = share.getShareInformation();
System.out.printf("total space of share = %d\n", info.getTotalSpace());
System.out.printf("free space of share = %d\n", info.getFreeSpace());

ShareInfo info = share.getShareInformation();
System.out.printf("total space of share = %d\n", info.getTotalSpace());
System.out.printf("free space of share = %d\n", info.getFreeSpace());

} finally {
session.close();
Expand Down
57 changes: 15 additions & 42 deletions src/main/java/com/hierynomus/smbj/share/DiskShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ public class DiskShare extends Share {

private static final Logger logger = LoggerFactory.getLogger(DiskShare.class);

protected ShareInfo shareInfo = null;
protected long attrExpiration = 0L;
protected static final long attrExpirationPeriod;

protected static final long DEFAULT_ATTR_EXPIRATION_PERIOD = 5000;

static {
long period = DEFAULT_ATTR_EXPIRATION_PERIOD;
try {
String value = System.getProperty("hierynomus.smb.client.attrExpirationPeriod");
if ( value != null ) {
period = Long.valueOf(value);
}
} catch (Exception e) {

}
attrExpirationPeriod = period;
}

public DiskShare(SmbPath smbPath, TreeConnect treeConnect) {
super(smbPath, treeConnect);
}
Expand Down Expand Up @@ -214,34 +195,26 @@ public FileInfo getFileInformation(SMB2FileId fileId) throws SMBApiException, Tr

/**
* Get Share Information for the current Disk Share
*
* @return the ShareInfo
* @throws SMBApiException
*/
public ShareInfo getShareInformation() throws TransportException, SMBApiException {
final String path = "";

if ( shareInfo != null && attrExpiration > System.currentTimeMillis() ) {
return shareInfo;
}

Directory directory = openDirectory(path, EnumSet.of(AccessMask.FILE_READ_ATTRIBUTES),
EnumSet.of(SMB2ShareAccess.FILE_SHARE_DELETE, SMB2ShareAccess.FILE_SHARE_WRITE,
SMB2ShareAccess.FILE_SHARE_READ),

Directory directory = openDirectory("",
EnumSet.of(AccessMask.FILE_READ_ATTRIBUTES), EnumSet.of(SMB2ShareAccess.FILE_SHARE_DELETE,
SMB2ShareAccess.FILE_SHARE_WRITE, SMB2ShareAccess.FILE_SHARE_READ),
SMB2CreateDisposition.FILE_OPEN);

try {
byte[] outputBuffer = queryInfoCommon(directory.getFileId(),
SMB2QueryInfoRequest.SMB2QueryInfoType.SMB2_0_INFO_FILESYSTEM,
null, null, FileSysemInformationClass.FileFsFullSizeInformation);

shareInfo = ShareInfo.parseFsFullSizeInformation(new Buffer.PlainBuffer(outputBuffer, Endian.LE));
attrExpiration = System.currentTimeMillis() + attrExpirationPeriod;

return shareInfo;

} catch (Buffer.BufferException e) {
throw new SMBRuntimeException(e);
}

byte[] outputBuffer = queryInfoCommon(directory.getFileId(),
SMB2QueryInfoRequest.SMB2QueryInfoType.SMB2_0_INFO_FILESYSTEM, null, null,
FileSysemInformationClass.FileFsFullSizeInformation);

try {
return ShareInfo.parseFsFullSizeInformation(new Buffer.PlainBuffer(outputBuffer, Endian.LE));
} catch (Buffer.BufferException e) {
throw new SMBRuntimeException(e);
}
}

/**
Expand Down

0 comments on commit 53970ed

Please sign in to comment.