Merge pull request #2958 from kapodamy/android5-temp-dir-issue
fix #2889
This commit is contained in:
commit
cc83991d8d
2 changed files with 24 additions and 9 deletions
|
@ -80,7 +80,7 @@ public abstract class Postprocessing implements Serializable {
|
||||||
|
|
||||||
private transient DownloadMission mission;
|
private transient DownloadMission mission;
|
||||||
|
|
||||||
private File tempFile;
|
private transient File tempFile;
|
||||||
|
|
||||||
Postprocessing(boolean reserveSpace, boolean worksOnSameFile, String algorithmName) {
|
Postprocessing(boolean reserveSpace, boolean worksOnSameFile, String algorithmName) {
|
||||||
this.reserveSpace = reserveSpace;
|
this.reserveSpace = reserveSpace;
|
||||||
|
@ -95,8 +95,12 @@ public abstract class Postprocessing implements Serializable {
|
||||||
|
|
||||||
public void cleanupTemporalDir() {
|
public void cleanupTemporalDir() {
|
||||||
if (tempFile != null && tempFile.exists()) {
|
if (tempFile != null && tempFile.exists()) {
|
||||||
|
try {
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,9 @@ public class DownloadManager {
|
||||||
Log.d(TAG, "Loading pending downloads from directory: " + mPendingMissionsDir.getAbsolutePath());
|
Log.d(TAG, "Loading pending downloads from directory: " + mPendingMissionsDir.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File tempDir = pickAvailableTemporalDir(ctx);
|
||||||
|
Log.i(TAG, "using '" + tempDir + "' as temporal directory");
|
||||||
|
|
||||||
for (File sub : subs) {
|
for (File sub : subs) {
|
||||||
if (!sub.isFile()) continue;
|
if (!sub.isFile()) continue;
|
||||||
if (sub.getName().equals(".tmp")) continue;
|
if (sub.getName().equals(".tmp")) continue;
|
||||||
|
@ -184,7 +187,7 @@ public class DownloadManager {
|
||||||
|
|
||||||
if (mis.psAlgorithm != null) {
|
if (mis.psAlgorithm != null) {
|
||||||
mis.psAlgorithm.cleanupTemporalDir();
|
mis.psAlgorithm.cleanupTemporalDir();
|
||||||
mis.psAlgorithm.setTemporalDir(pickAvailableTemporalDir(ctx));
|
mis.psAlgorithm.setTemporalDir(tempDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
mis.metadata = sub;
|
mis.metadata = sub;
|
||||||
|
@ -513,13 +516,21 @@ public class DownloadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static File pickAvailableTemporalDir(@NonNull Context ctx) {
|
static File pickAvailableTemporalDir(@NonNull Context ctx) {
|
||||||
if (isDirectoryAvailable(ctx.getExternalFilesDir(null)))
|
File dir = ctx.getExternalFilesDir(null);
|
||||||
return ctx.getExternalFilesDir(null);
|
if (isDirectoryAvailable(dir)) return dir;
|
||||||
else if (isDirectoryAvailable(ctx.getFilesDir()))
|
|
||||||
return ctx.getFilesDir();
|
dir = ctx.getFilesDir();
|
||||||
|
if (isDirectoryAvailable(dir)) return dir;
|
||||||
|
|
||||||
// this never should happen
|
// this never should happen
|
||||||
return ctx.getDir("tmp", Context.MODE_PRIVATE);
|
dir = ctx.getDir("muxing_tmp", Context.MODE_PRIVATE);
|
||||||
|
if (isDirectoryAvailable(dir)) return dir;
|
||||||
|
|
||||||
|
// fallback to cache dir
|
||||||
|
dir = ctx.getCacheDir();
|
||||||
|
if (isDirectoryAvailable(dir)) return dir;
|
||||||
|
|
||||||
|
throw new RuntimeException("Not temporal directories are available");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
Loading…
Reference in a new issue