From 1ecc9b9a572ddbdb49f7355bd9d77f902be4bd74 Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Thu, 9 May 2024 08:53:58 -0700 Subject: [PATCH] cavern: add QuotaPlugin.getBytesUsed method --- .../java/org/opencadc/cavern/nodes/NoQuotaPlugin.java | 9 ++++++++- .../main/java/org/opencadc/cavern/nodes/NodeUtil.java | 4 +++- .../java/org/opencadc/cavern/nodes/QuotaPlugin.java | 10 +++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java b/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java index d99feb0e..a4cbd489 100644 --- a/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java @@ -71,7 +71,8 @@ import org.apache.log4j.Logger; /** - * + * Default plugin that does nothing. + * * @author pdowler */ public class NoQuotaPlugin implements QuotaPlugin { @@ -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; + } } diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java b/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java index 6347b4c8..18d83177 100644 --- a/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java @@ -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(); diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java b/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java index 3cbdd14b..72e2f553 100644 --- a/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java @@ -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); @@ -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); }