Skip to content

Commit

Permalink
cavern: PutAction (files endpoint) can create a file if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Dec 18, 2023
1 parent d596c7b commit 3d14726
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cavern/src/main/java/org/opencadc/cavern/files/PutAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
import org.opencadc.vospace.VOSURI;

/**
*
* @author pdowler
* @author majorb
* @author jeevesh
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 3d14726

Please sign in to comment.