forked from j62/ctbrec
Improve deleteIfTooShort method
If a directory does not exist, it returns true. If the directory is empty, it deletes the directory and empty parent directories and returns true.
This commit is contained in:
parent
fba3a72167
commit
75a625bbe0
|
@ -792,23 +792,32 @@ public class LocalRecorder implements Recorder {
|
||||||
// TODO maybe get file size and bitrate and check, if the values are plausible
|
// TODO maybe get file size and bitrate and check, if the values are plausible
|
||||||
// we could also compare the length with the time elapsed since starting the recording
|
// we could also compare the length with the time elapsed since starting the recording
|
||||||
private boolean deleteIfTooShort(Download download) {
|
private boolean deleteIfTooShort(Download download) {
|
||||||
|
try {
|
||||||
|
File target = download.getTarget();
|
||||||
|
if(!target.exists()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(target.isDirectory()) {
|
||||||
|
if(target.list() == null || target.list().length == 0) {
|
||||||
|
deleteDirectory(target);
|
||||||
|
deleteEmptyParents(target);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(target.length() == 0) {
|
||||||
|
Files.delete(target.toPath());
|
||||||
|
deleteEmptyParents(target.getParentFile());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long minimumLengthInSeconds = Config.getInstance().getSettings().minimumLengthInSeconds;
|
long minimumLengthInSeconds = Config.getInstance().getSettings().minimumLengthInSeconds;
|
||||||
if(minimumLengthInSeconds <= 0) {
|
if(minimumLengthInSeconds <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
LOG.debug("Determining video length for {}", download.getTarget());
|
LOG.debug("Determining video length for {}", download.getTarget());
|
||||||
File target = download.getTarget();
|
|
||||||
if(target.isDirectory()) {
|
|
||||||
if(!target.exists() || target.list() == null || target.list().length == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(!target.exists() || target.length() == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double duration = 0;
|
double duration = 0;
|
||||||
if(target.isDirectory()) {
|
if(target.isDirectory()) {
|
||||||
|
|
Loading…
Reference in New Issue