Merge "Call access(2) on all files/dirs modified by Mtp" into pi-dev

am: 01f41f96fe

Change-Id: I7c329a8cdff834a24a3e0ef3f82387421084b5de
This commit is contained in:
Jerry Zhang
2018-05-15 14:55:19 -07:00
committed by android-build-merger
2 changed files with 14 additions and 4 deletions

View File

@@ -35,6 +35,9 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Files;
import android.provider.MediaStore.MediaColumns;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
@@ -560,6 +563,13 @@ public class MtpDatabase implements AutoCloseable {
return MtpConstants.RESPONSE_GENERAL_ERROR;
Path newPath = obj.getPath();
boolean success = oldPath.toFile().renameTo(newPath.toFile());
try {
Os.access(oldPath.toString(), OsConstants.F_OK);
Os.access(newPath.toString(), OsConstants.F_OK);
} catch (ErrnoException e) {
// Ignore. Could fail if the metadata was already updated.
}
if (!mManager.endRenameObject(obj, oldPath.getFileName().toString(), success)) {
Log.e(TAG, "Failed to end rename object");
}

View File

@@ -104,10 +104,10 @@ public class MtpStorageManagerTest {
mainStorageDir = createNewDir(TEMP_DIR_FILE);
secondaryStorageDir = createNewDir(TEMP_DIR_FILE);
StorageVolume mainStorage = new StorageVolume("1", mainStorageDir, "", true, false, true,
false, -1, UserHandle.CURRENT, "", "");
StorageVolume secondaryStorage = new StorageVolume("2", secondaryStorageDir, "", false,
false, true, false, -1, UserHandle.CURRENT, "", "");
StorageVolume mainStorage = new StorageVolume("1", mainStorageDir, mainStorageDir,
"", true, false, true, false, -1, UserHandle.CURRENT, "", "");
StorageVolume secondaryStorage = new StorageVolume("2", secondaryStorageDir,
secondaryStorageDir, "", false, false, true, false, -1, UserHandle.CURRENT, "", "");
objectsAdded = new ArrayList<>();
objectsRemoved = new ArrayList<>();