Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK-612 - OpenCGA files/link raises a NullPointExeption if it has no read access to the file #2241

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ public OpenCGAResult<File> link(String studyStr, FileLinkParams params, boolean
auditManager.auditCreate(userId, Enums.Action.LINK, Enums.Resource.FILE, params.getUri(), "",
study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR,
new Error(0, "", e2.getMessage())));
throw new CatalogException(e2.getMessage(), e2);
throw e2;
pfurio marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -3506,7 +3506,7 @@ public FileVisitResult preVisitDirectory(URI dir, BasicFileAttributes attrs) thr
}
}
} catch (CatalogException e) {
logger.error("An error occurred when trying to create folder {}", dir.toString());
throw new IOException("An error occurred when trying to create folder " + dir, e);
}

return FileVisitResult.CONTINUE;
Expand Down Expand Up @@ -3581,7 +3581,7 @@ public FileVisitResult visitFile(URI fileUri, BasicFileAttributes attrs) throws
+ ". There is already a file in the path " + destinyPath + " with the same name.");
}
} catch (CatalogException e) {
logger.error(e.getMessage());
throw new IOException(e);
}

return FileVisitResult.CONTINUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ public void testLinkUserWithNoWritePermissions() throws CatalogException {
fileManager.link(studyFqn, Paths.get(reference).toUri(), "", null, analystToken).first();
}

@Test
public void testLinkFileWithoutReadPermissions() throws IOException, CatalogException {
java.io.File file = createDebugFile("/tmp/file_" + RandomStringUtils.randomAlphanumeric(5) + ".vcf");
Files.setPosixFilePermissions(Paths.get(file.toURI()), new HashSet<>());
thrown.expect(CatalogIOException.class);
thrown.expectMessage("read VariantSource");
fileManager.link(studyFqn, new FileLinkParams().setUri(file.getPath()), false, token);
}

@Test
public void createDirectoryTest() throws CatalogException {
FileCreateParams params = new FileCreateParams()
Expand Down