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

Add DO_NOT_DELETE file below marker directory (fixes #131) #133

Closed
wants to merge 2 commits into from
Closed
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 @@ -83,6 +83,7 @@ public class FolderActivity extends SyncthingActivity
private static final int CHOOSE_FOLDER_REQUEST = 3459;

private static final String FOLDER_MARKER_NAME = ".stfolder";
private static final String DO_NOT_DELETE_NAME = "DO_NOT_DELETE";
// private static final String IGNORE_FILE_NAME = ".stignore";

private Folder mFolder;
Expand Down Expand Up @@ -516,20 +517,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
.show();
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
mFolderUri != null &&
mFolder.type.equals(Constants.FOLDER_TYPE_SEND_ONLY)) {
/**
* Normally, syncthing takes care of creating the ".stfolder" marker.
* This fails on newer android versions if the syncthing binary only has
* readonly access on the path and the user tries to configure a
* sendonly folder. To fix this, we'll precreate the marker using java code.
*/
DocumentFile dfFolder = DocumentFile.fromTreeUri(this, mFolderUri);
if (dfFolder != null) {
Log.v(TAG, "Creating new directory " + mFolder.path + File.separator + FOLDER_MARKER_NAME);
dfFolder.createDirectory(FOLDER_MARKER_NAME);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mFolderUri != null) {
preCreateFolderMarker();
}
getApi().createFolder(mFolder);
finish();
Expand All @@ -545,6 +534,35 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

private void preCreateFolderMarker() {
Boolean createFolderMarker = mFolder.type.equals(Constants.FOLDER_TYPE_SEND_ONLY);
/**
* Create a "DO_NOT_DELETE" file below the ".stfolder" marker directory.
* This is a workaround for https://github.com/Catfriend1/syncthing-android/issues/131
* where empty directories get cleaned by Xiaomi MIUI's "Cleaner" system app. Folders
* are then left in "Error" state.
*/
Boolean createDoNotDeleteFile = "xiaomi".equalsIgnoreCase(Build.MANUFACTURER);
if (createFolderMarker || createDoNotDeleteFile) {
/**
* Normally, syncthing takes care of creating the ".stfolder" marker.
* This fails on newer android versions if the syncthing binary only has
* readonly access on the path and the user tries to configure a
* sendonly folder. To fix this, we'll precreate the marker using java code.
*/
DocumentFile dfFolder = DocumentFile.fromTreeUri(this, mFolderUri);
if (dfFolder != null) {
Log.v(TAG, "Creating new directory " + mFolder.path + File.separator + FOLDER_MARKER_NAME);
dfFolder.createDirectory(FOLDER_MARKER_NAME);
if (createDoNotDeleteFile) {
Log.v(TAG, "Creating new file " + mFolder.path + File.separator + FOLDER_MARKER_NAME +
File.separator + DO_NOT_DELETE_NAME);
// dfFolder.createFile(FOLDER_MARKER_NAME + File.separator + DO_NOT_DELETE_NAME);
}
}
}
}

private void showDeleteDialog(){
mDeleteDialog = createDeleteDialog();
mDeleteDialog.show();
Expand Down