Skip to content

Commit

Permalink
Default folder path: Home shortcut (~) broken (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Catfriend1 authored Dec 10, 2024
1 parent be41010 commit a0d9628
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.nutomic.syncthingandroid.model.SystemStatus;
import com.nutomic.syncthingandroid.model.SystemVersion;
import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.util.FileUtils;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -594,6 +595,11 @@ public List<Folder> getFolders() {
synchronized (mConfigLock) {
folders = deepCopy(mConfig.folders, new TypeToken<List<Folder>>(){}.getType());
}
for (Folder folder : folders) {
if (folder.path.startsWith("~/")) {
folder.path = folder.path.replaceFirst("^~", FileUtils.getInternalStorageRootAbsolutePath());
}
}
Collections.sort(folders, FOLDERS_COMPARATOR);
return folders;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ public List<Folder> getFolders() {
Folder folder = new Folder();
folder.id = getAttributeOrDefault(r, "id", "");
folder.label = getAttributeOrDefault(r, "label", folder.label);

folder.path = getAttributeOrDefault(r, "path", "");
if (folder.path.startsWith("~/")) {
folder.path = folder.path.replaceFirst("^~", FileUtils.getInternalStorageRootAbsolutePath());
}

folder.type = getAttributeOrDefault(r, "type", Constants.FOLDER_TYPE_SEND_RECEIVE);
folder.autoNormalize = getAttributeOrDefault(r, "autoNormalize", folder.autoNormalize);
folder.fsWatcherDelayS =getAttributeOrDefault(r, "fsWatcherDelayS", folder.fsWatcherDelayS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ public static void deleteDirectoryRecursively(java.nio.file.Path pathToDelete) t
.map(java.nio.file.Path::toFile)
.forEach(File::delete);
}

/**
* Expands the "~" path.
* Result: e.g. /storage/emulated/0
*/
public static String getInternalStorageRootAbsolutePath() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}

/**
* Derives the mime type from file extension.
Expand Down

0 comments on commit a0d9628

Please sign in to comment.