File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed
main/java/net/snowflake/client/core
test/java/net/snowflake/client/core Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -141,14 +141,18 @@ synchronized FileCacheManager build() {
141141 }
142142 if (!cacheDir .exists ()) {
143143 try {
144- Files .createDirectories (
145- cacheDir .toPath (),
146- PosixFilePermissions .asFileAttribute (
147- Stream .of (
148- PosixFilePermission .OWNER_READ ,
149- PosixFilePermission .OWNER_WRITE ,
150- PosixFilePermission .OWNER_EXECUTE )
151- .collect (Collectors .toSet ())));
144+ if (!isWindows () && onlyOwnerPermissions ) {
145+ Files .createDirectories (
146+ cacheDir .toPath (),
147+ PosixFilePermissions .asFileAttribute (
148+ Stream .of (
149+ PosixFilePermission .OWNER_READ ,
150+ PosixFilePermission .OWNER_WRITE ,
151+ PosixFilePermission .OWNER_EXECUTE )
152+ .collect (Collectors .toSet ())));
153+ } else {
154+ Files .createDirectories (cacheDir .toPath ());
155+ }
152156 } catch (IOException e ) {
153157 logger .info (
154158 "Failed to create the cache directory: {}. Ignored. {}" ,
Original file line number Diff line number Diff line change @@ -199,4 +199,17 @@ private Path createSymlink() throws IOException {
199199 }
200200 return Files .createSymbolicLink (link , cacheFile .toPath ());
201201 }
202+
203+ @ Test
204+ void shouldCreateDirAndFile () {
205+ String tmpDirPath = System .getProperty ("java.io.tmpdir" );
206+ String cacheDirPath = tmpDirPath + File .separator + "snowflake-cache-dir" ;
207+ System .setProperty ("FILE_CACHE_MANAGER_SHOULD_CREATE_DIR_AND_FILE" , cacheDirPath );
208+ FileCacheManager .builder ()
209+ .setOnlyOwnerPermissions (false )
210+ .setCacheDirectorySystemProperty ("FILE_CACHE_MANAGER_SHOULD_CREATE_DIR_AND_FILE" )
211+ .setBaseCacheFileName ("cache-file" )
212+ .build ();
213+ assertTrue (new File (tmpDirPath ).exists ());
214+ }
202215}
You can’t perform that action at this time.
0 commit comments