Skip to content

Commit

Permalink
cavern: add QuotaPlugin.getBytesUsed method
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed May 9, 2024
1 parent f32ac29 commit 1ecc9b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
import org.apache.log4j.Logger;

/**
*
* Default plugin that does nothing.
*
* @author pdowler
*/
public class NoQuotaPlugin implements QuotaPlugin {
Expand All @@ -90,4 +91,10 @@ public Long getQuota(Path directory) {
public void setQuota(Path directory, Long quota) {
log.debug("setQuota: " + directory + " -> " + quota + " IGNORED");
}

@Override
public Long getBytesUsed(Path directory) {
log.debug("getBytesUsed: " + directory + " IGNORED");
return null;
}
}
4 changes: 3 additions & 1 deletion cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ Node pathToNode(Path p, boolean getAttrs)
PosixFileAttributes attrs = Files.readAttributes(p,
PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
if (attrs.isDirectory()) {
ret = new ContainerNode(p.getFileName().toString());
ContainerNode cn = new ContainerNode(p.getFileName().toString());
cn.bytesUsed = quotaImpl.getBytesUsed(p);
ret = cn;
} else if (attrs.isRegularFile()) {
DataNode dn = new DataNode(p.getFileName().toString());
dn.bytesUsed = attrs.size();
Expand Down
10 changes: 9 additions & 1 deletion cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public interface QuotaPlugin {
* Get the current quota in bytes.
*
* @param directory directory to check
* @return current quota in bytes
* @return current quota in bytes, null if not set or not supported
*/
public Long getQuota(Path directory);

Expand All @@ -92,4 +92,12 @@ public interface QuotaPlugin {
* @param quota the new quota, null to clear the current quota
*/
public void setQuota(Path directory, Long quota);

/**
* Get the number of bytes used in a directory (recursive).
*
* @param directory the target directory
* @return bytes used in target directory, or null of not available for the target path
*/
public Long getBytesUsed(Path directory);
}

0 comments on commit 1ecc9b9

Please sign in to comment.