From 3d14726b7af8b486a6973559ba096005b1c027c2 Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Mon, 18 Dec 2023 12:11:24 -0800 Subject: [PATCH] cavern: PutAction (files endpoint) can create a file if it doesn't exist --- .../java/org/opencadc/cavern/files/PutAction.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cavern/src/main/java/org/opencadc/cavern/files/PutAction.java b/cavern/src/main/java/org/opencadc/cavern/files/PutAction.java index 095c2456..cf0bd171 100644 --- a/cavern/src/main/java/org/opencadc/cavern/files/PutAction.java +++ b/cavern/src/main/java/org/opencadc/cavern/files/PutAction.java @@ -98,7 +98,7 @@ import org.opencadc.vospace.VOSURI; /** - * + * @author pdowler * @author majorb * @author jeevesh */ @@ -174,6 +174,13 @@ public void doAction() throws Exception { throw new IllegalArgumentException("not a data node"); } node = (DataNode) n; + if (node == null) { + log.warn("target node: " + node + ": creating"); + node = new DataNode(nodeURI.getName()); + node.owner = caller; + node.parent = cn; + nodePersistence.put(node); + } // check write permission if (!preauthGranted) { @@ -197,8 +204,9 @@ public void doAction() throws Exception { //Files.copy(vis, target, StandardCopyOption.REPLACE_EXISTING); // truncate: do not recreate file with wrong owner + StandardOpenOption openOption = StandardOpenOption.TRUNCATE_EXISTING; DigestOutputStream out = new DigestOutputStream( - Files.newOutputStream(target, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING), md); + Files.newOutputStream(target, StandardOpenOption.WRITE, openOption), md); ByteCountOutputStream bcos = new ByteCountOutputStream(out); MultiBufferIO io = new MultiBufferIO(); io.copy(in, bcos); @@ -223,7 +231,7 @@ public void doAction() throws Exception { // update Node node.owner = caller; - node.ownerID = identityManager.toPosixPrincipal(caller); + node.ownerID = null; // just in case log.debug(nodeURI + " MD5: " + propValue); NodeProperty csp = node.getProperty(VOS.PROPERTY_URI_CONTENTMD5);