WIP Debug storage writability test
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
parent
8633ed6ebd
commit
c2fcd7e553
2 changed files with 72 additions and 2 deletions
|
@ -143,6 +143,8 @@ public class StoragePathManager
|
|||
}
|
||||
// Add the trailing separator because the native code assumes that all paths have it.
|
||||
path = StorageUtils.addTrailingSeparator(path);
|
||||
dir = new File(path);
|
||||
|
||||
final boolean isCurrent = path.equals(configPath);
|
||||
final long totalSize = dir.getTotalSpace();
|
||||
final long freeSize = dir.getUsableSpace();
|
||||
|
@ -215,11 +217,28 @@ public class StoragePathManager
|
|||
LOGGER.w(TAG, "Not a directory: " + commentedPath);
|
||||
return;
|
||||
}
|
||||
if (!dir.canWrite() || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
|
||||
|
||||
// DEBUG
|
||||
if (!dir.canWrite())
|
||||
{
|
||||
LOGGER.w(TAG, " canWrite == false: " + commentedPath);
|
||||
}
|
||||
if (!dir.canRead())
|
||||
{
|
||||
LOGGER.w(TAG, " canRead == false: " + commentedPath);
|
||||
}
|
||||
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
|
||||
{
|
||||
LOGGER.w(TAG, " mounted readonly: " + commentedPath);
|
||||
}
|
||||
|
||||
// Do a test directory creation test in case dir.canWrite() gives a false negative.
|
||||
if (!StorageUtils.isDirWritable(dir))
|
||||
{
|
||||
isReadonly = true;
|
||||
commentedPath = "read-only " + commentedPath;
|
||||
}
|
||||
// DEBUG
|
||||
|
||||
if (TextUtils.isEmpty(label))
|
||||
label = isInternal ? mContext.getString(R.string.maps_storage_internal)
|
||||
|
|
|
@ -33,6 +33,54 @@ public class StorageUtils
|
|||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.STORAGE);
|
||||
private final static String TAG = StorageUtils.class.getSimpleName();
|
||||
|
||||
public static boolean isDirWritable(File dir)
|
||||
{
|
||||
LOGGER.d(TAG, "isDirWritable: checking " + dir.getPath());
|
||||
if (!dir.isDirectory())
|
||||
{
|
||||
LOGGER.w(TAG, "isDirWritable: not a dir");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dir.list() == null)
|
||||
LOGGER.w(TAG, "isDirWritable: list() returned null");
|
||||
|
||||
final File newDir = new File(dir, "om_test_dir");
|
||||
if (!newDir.mkdir())
|
||||
LOGGER.w(TAG, "isDirWritable: not created");
|
||||
if (!newDir.exists())
|
||||
{
|
||||
LOGGER.w(TAG, "isDirWritable: created, but not exists");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!newDir.canWrite())
|
||||
LOGGER.w(TAG, "isDirWritable: created, but not writable");
|
||||
if (!newDir.canRead())
|
||||
LOGGER.w(TAG, "isDirWritable: created, but not readable");
|
||||
if (newDir.list() == null)
|
||||
LOGGER.w(TAG, "isDirWritable: created, but list() returns null");
|
||||
|
||||
if (!newDir.delete())
|
||||
LOGGER.w(TAG, "isDirWritable: created, but not deleted");
|
||||
|
||||
File testFile = new File(dir, "220515");
|
||||
if (testFile.exists())
|
||||
{
|
||||
LOGGER.i(TAG, "isDirWritable: 220515/ exists!");
|
||||
if (!testFile.canRead())
|
||||
LOGGER.w(TAG, "isDirWritable: 220515/ is not readable");
|
||||
}
|
||||
testFile = new File(dir, "220515/World.mwm");
|
||||
if (testFile.exists()) {
|
||||
LOGGER.i(TAG, "isDirWritable: 220515/World.mwm exists!");
|
||||
if (!testFile.canRead())
|
||||
LOGGER.w(TAG, "isDirWritable: 220515/World.mwm is not readable");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getApkPath(@NonNull Application application)
|
||||
{
|
||||
|
@ -168,7 +216,10 @@ public class StorageUtils
|
|||
{
|
||||
File[] list = dir.listFiles();
|
||||
if (list == null)
|
||||
{
|
||||
LOGGER.w(TAG, "listFilesRecursively listFiles() returned null for " + dir.getPath());
|
||||
return;
|
||||
}
|
||||
|
||||
for (File file : list)
|
||||
{
|
||||
|
@ -191,7 +242,7 @@ public class StorageUtils
|
|||
final File[] list = dir.listFiles();
|
||||
if (list == null)
|
||||
{
|
||||
LOGGER.w(TAG, "getDirSizeRecursively dirFiles returned null");
|
||||
LOGGER.w(TAG, "getDirSizeRecursively listFiles() returned null for " + dir.getPath());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue