From 53970ed2ca9a7bd39dc4acbe23f78a36911a1dde Mon Sep 17 00:00:00 2001 From: Mark Niggemann Date: Tue, 13 Dec 2016 09:46:00 -0600 Subject: [PATCH] Updating due to review commentary. --- src/it/java/SmbjTest.java | 8 +-- .../com/hierynomus/smbj/share/DiskShare.java | 57 +++++-------------- 2 files changed, 19 insertions(+), 46 deletions(-) diff --git a/src/it/java/SmbjTest.java b/src/it/java/SmbjTest.java index 1201bbea..9a46e41b 100644 --- a/src/it/java/SmbjTest.java +++ b/src/it/java/SmbjTest.java @@ -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(); diff --git a/src/main/java/com/hierynomus/smbj/share/DiskShare.java b/src/main/java/com/hierynomus/smbj/share/DiskShare.java index ce5b2e27..cc2337f0 100644 --- a/src/main/java/com/hierynomus/smbj/share/DiskShare.java +++ b/src/main/java/com/hierynomus/smbj/share/DiskShare.java @@ -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); } @@ -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); + } } /**