Skip to content

Commit

Permalink
invoking media scanner on moved files, too, see GH issue #336
Browse files Browse the repository at this point in the history
  • Loading branch information
wolpi committed Mar 29, 2024
1 parent 476676a commit 155a7b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion primitiveFTPd/src/org/primftpd/filesystem/FsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ public boolean delete() {
public boolean move(FsFile<T> destination) {
logger.trace("[{}] move({})", name, destination.getAbsolutePath());
postClientAction(ClientActionEvent.ClientAction.RENAME);
return file.renameTo(new File(destination.getAbsolutePath()));
boolean success = file.renameTo(new File(destination.getAbsolutePath()));
if (success) {
Utils.mediaScanFile(pftpdService.getContext(), getAbsolutePath());
}
return success;
}

public List<T> listFiles() {
Expand Down
6 changes: 5 additions & 1 deletion primitiveFTPd/src/org/primftpd/filesystem/RootFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public boolean delete() {
public boolean move(RootFile<T> destination) {
logger.trace("[{}] move({})", name, destination.getAbsolutePath());
postClientAction(ClientActionEvent.ClientAction.RENAME);
return runCommand("mv " + escapePath(absPath) + " " + escapePath(destination.getAbsolutePath()));
boolean success = runCommand("mv " + escapePath(absPath) + " " + escapePath(destination.getAbsolutePath()));
if (success) {
Utils.mediaScanFile(pftpdService.getContext(), getAbsolutePath());
}
return success;
}

public List<T> listFiles() {
Expand Down
6 changes: 6 additions & 0 deletions primitiveFTPd/src/org/primftpd/filesystem/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import android.net.Uri;
import android.os.AsyncTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -13,6 +16,8 @@

public class Utils {

protected static Logger logger = LoggerFactory.getLogger(Utils.class);

static String absolute(String rel, String workingDir) {
if (rel.charAt(0) == '/') {
return rel;
Expand Down Expand Up @@ -91,6 +96,7 @@ public void onScanCompleted(String path, Uri uri) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
logger.info("media scanning file: {}", absPath);
con.scanFile(absPath, null);
return null;
}
Expand Down

0 comments on commit 155a7b0

Please sign in to comment.