Skip to content

Commit fdb7629

Browse files
committed
safely set datafile owner
1 parent b84ba39 commit fdb7629

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateNewDataFilesCommand.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,30 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
610610

611611

612612
if (datafile != null) {
613-
if(newStorageIdentifier != null) {
614-
//Direct upload case
615-
//Improve the MIMEType
616-
String type = determineRemoteFileType(datafile, fileName);
617-
if (!StringUtils.isBlank(type)) {
618-
//Use rules for deciding when to trust browser supplied type
619-
if (useRecognizedType(finalType, type)) {
620-
datafile.setContentType(type);
613+
if (newStorageIdentifier != null) {
614+
// Direct upload case
615+
// Improve the MIMEType
616+
// Need the owner for the StorageIO class to get the file/S3 path from the
617+
// storageIdentifier
618+
//Currently owner is null, but using this falg will avoid making changes here if that isn't true in the future
619+
boolean ownerSet = datafile.getOwner() != null;
620+
if (!ownerSet) {
621+
datafile.setOwner(version.getDataset());
622+
}
623+
String type = determineRemoteFileType(datafile, fileName);
624+
if (!StringUtils.isBlank(type)) {
625+
626+
// Use rules for deciding when to trust browser supplied type
627+
if (useRecognizedType(finalType, type)) {
628+
datafile.setContentType(type);
629+
}
630+
logger.fine("Supplied type: " + suppliedContentType + ", finalType: " + finalType);
631+
}
632+
// Avoid changing
633+
if (!ownerSet) {
634+
datafile.setOwner(null);
621635
}
622-
logger.fine("Supplied type: " + suppliedContentType + ", finalType: " + finalType);
623636
}
624-
}
625-
626637

627638
if (warningMessage != null) {
628639
createIngestFailureReport(datafile, warningMessage);

0 commit comments

Comments
 (0)