Check OS before hiding internal folder

This commit is contained in:
Simon Grimme
2022-10-15 02:01:39 +02:00
parent 317c692056
commit e6ed869bac
3 changed files with 14 additions and 9 deletions
@@ -10,18 +10,16 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.*;
import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Locale;
import java.util.Properties;
import java.util.stream.StreamSupport;
@@ -48,9 +46,11 @@ public class FilesystemConfig {
*/
@EventListener(ApplicationReadyEvent.class)
public void hideInternalFolderOnDOS() throws IOException {
if (!isRunningOnWindows()) return;
Path internalFolder = Paths.get("%s/%s".formatted(firstLibraryPath, INTERNAL_FOLDER_NAME));
if(!Files.exists(internalFolder) || !Files.isDirectory(internalFolder)) return;
if (!Files.exists(internalFolder) || !Files.isDirectory(internalFolder)) return;
Files.setAttribute(internalFolder, "dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
}
@@ -59,11 +59,11 @@ public class FilesystemConfig {
public void setConfigurableEnvironment(ConfigurableEnvironment env) {
Properties props = new Properties();
if(!StringUtils.hasText(dbPath)) {
if (!StringUtils.hasText(dbPath)) {
props.setProperty("gameyfin.db", "%s/%s/db".formatted(firstLibraryPath, INTERNAL_FOLDER_NAME));
}
if(!StringUtils.hasText(cachePath)) {
if (!StringUtils.hasText(cachePath)) {
props.setProperty("gameyfin.cache", "%s/%s/cache".formatted(firstLibraryPath, INTERNAL_FOLDER_NAME));
}
@@ -72,6 +72,7 @@ public class FilesystemConfig {
/**
* This bean is needed so Spring initializes the data source after we are done messing with the configuration environment
*
* @return DataSource
*/
@ConfigurationProperties(prefix = "spring.datasource")
@@ -101,4 +102,8 @@ public class FilesystemConfig {
return props;
}
private boolean isRunningOnWindows() {
return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows");
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "frontend",
"version": "1.2.2-SNAPSHOT",
"version": "1.2.3-SNAPSHOT",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "frontend",
"version": "1.2.2-SNAPSHOT",
"version": "1.2.3-SNAPSHOT",
"dependencies": {
"@angular/animations": "^14.0.0",
"@angular/cdk": "^14.1.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.2.2-SNAPSHOT",
"version": "1.2.3-SNAPSHOT",
"scripts": {
"ng": "ng",
"start": "ng serve",