Skip to content
Snippets Groups Projects
Commit 02c3a41b authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Some minor fixes

parent 4fc03d51
No related branches found
No related tags found
No related merge requests found
......@@ -7,22 +7,15 @@ package it.inaf.ia2.transfer.controller;
import it.inaf.ia2.transfer.persistence.model.FileInfo;
import it.inaf.ia2.transfer.persistence.FileDAO;
import it.inaf.ia2.transfer.persistence.JobDAO;
import it.inaf.ia2.transfer.service.PutFileService;
import it.inaf.oats.vospace.exception.InvalidArgumentException;
import it.inaf.oats.vospace.exception.NodeNotFoundException;
import it.inaf.oats.vospace.exception.QuotaExceededException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.io.UncheckedIOException;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.DatatypeConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -92,8 +85,8 @@ public class PutFileController extends FileController {
try (InputStream in = file != null ? file.getInputStream() : request.getInputStream()) {
putFileService.storeFileFromInputStream(fileInfo, in, remainingQuota);
} catch (Exception ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
} finally {
......
......@@ -11,6 +11,7 @@ import it.inaf.oats.vospace.exception.QuotaExceededException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -51,8 +52,10 @@ public class PutFileService {
try {
Files.copy(sourceFile.toPath(), destinationFile.toPath());
this.finalizeFile(sourceFileInfo, destinationFileInfo, destinationFile, remainingQuota);
} catch (Exception e) {
} catch (IOException e) {
destinationFile.delete();
throw new UncheckedIOException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
......@@ -70,7 +73,10 @@ public class PutFileService {
try {
Files.copy(is, destinationFile.toPath());
this.finalizeFile(sourceFileInfo, destinationFileInfo, destinationFile, remainingQuota);
} catch (Exception e) {
} catch (IOException e) {
destinationFile.delete();
throw new UncheckedIOException(e);
} catch (NoSuchAlgorithmException e) {
destinationFile.delete();
throw new RuntimeException(e);
}
......@@ -114,6 +120,7 @@ public class PutFileService {
String md5Checksum = makeMD5Checksum(destinationFile);
// TODO: discuss if mismatches lead to taking actions
if (sourceFileInfo != null) {
if (!Objects.equals(sourceFileInfo.getContentLength(), fileSize)) {
LOG.warn("Destination file size mismatch with source");
......
......@@ -299,6 +299,7 @@ public class PutFileControllerTest {
fileInfo.setPublic(false);
when(fileDao.getFileInfo(any())).thenReturn(Optional.of(fileInfo));
when(fileDao.setBusy(any(), any())).thenReturn(1);
return fileInfo;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment