Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -265,7 +265,7 @@ synchronized <T> T withLock(Supplier<T> supplier) {
synchronized JsonNode readCacheFile() {
try {
if (!FileUtil.exists(cacheFile)) {
logger.debug("Cache file doesn't exist. File: {}", cacheFile);
logger.debug("Cache file doesn't exist. Ignoring read. File: {}", cacheFile);
return null;
}

Expand All @@ -290,7 +290,9 @@ synchronized JsonNode readCacheFile() {
synchronized void writeCacheFile(JsonNode input) {
logger.debug("Writing cache file. File: {}", cacheFile);
try {
if (input == null) {
if (input == null || !FileUtil.exists(cacheFile)) {
logger.debug(
"Cache file doesn't exist or input is null. Ignoring write. File: {}", cacheFile);
return;
}
try (Writer writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void throwWhenReadCacheFileWithPermissionDifferentThanReadWriteForUserTes

@Test
@RunOnLinuxOrMac
public void notThrowExceptionWhenCacheFolderIsNotAccessible() throws IOException {
public void notThrowExceptionWhenCacheFolderIsNotAccessibleWhenReadFromCache()
throws IOException {
try {
Files.setPosixFilePermissions(
cacheFile.getParentFile().toPath(), PosixFilePermissions.fromString("---------"));
Expand All @@ -124,6 +125,31 @@ public void notThrowExceptionWhenCacheFolderIsNotAccessible() throws IOException
}
}

@Test
@RunOnLinuxOrMac
public void notThrowExceptionWhenCacheFolderIsNotAccessibleWhenWriteToCache() throws IOException {
String tmpDirPath = System.getProperty("java.io.tmpdir");
String cacheDirPath = tmpDirPath + File.separator + "snowflake-cache-dir-noaccess";
System.setProperty("FILE_CACHE_MANAGER_CACHE_PATH", cacheDirPath);
try {
Files.createDirectory(
Paths.get(cacheDirPath),
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("---------")));

FileCacheManager fcm =
FileCacheManager.builder()
.setOnlyOwnerPermissions(false)
.setCacheDirectorySystemProperty("FILE_CACHE_MANAGER_CACHE_PATH")
.setCacheDirectoryEnvironmentVariable("NONEXISTENT")
.setBaseCacheFileName("cache-file")
.build();
assertDoesNotThrow(() -> fcm.writeCacheFile(mapper.createObjectNode()));
} finally {
Files.deleteIfExists(Paths.get(cacheDirPath));
System.clearProperty("FILE_CACHE_MANAGER_CACHE_PATH");
}
}

@Test
@RunOnLinuxOrMac
public void throwWhenOverrideCacheFileHasDifferentOwnerThanCurrentUserTest() {
Expand Down