git.iko.soy/maciek134/podphoenix
on main help sign in
Simplified orphan file logic
commit008d7b6ea3578c7b9ecef055c0c11de740e80855 authorNekhelesh Ramananthan <krnekhelesh@gmail.com> dateMon 5 Dec 2016, 23:17 (10 years ago) parenta0c5dc2
1 file changed+16−37
app/ui/SettingsPage.qml+16−37
app/ui/SettingsPage.qml+16−37
@@ -376,54 +376,33 @@ pointing at invalid files have also been cleaned up.")
376376
377377 // Go through every downloaded file and check if they are orphaned
378378 for (var l = 0; l < filelist.length; l++) {
379− var isOrphanFile = true
380−
381− // Go through every podcast
382− for (var i=0; i < rs.rows.length; i++) {
383− var podcast = rs.rows.item(i);
384− var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=?", [podcast.rowid]);
385−
386− // Go through every episode in the podcast
387− for (var j=0; j < rs2.rows.length; j++) {
388− var episode = rs2.rows.item(j);
389− if (episode.downloadedfile) {
390− if(fileManager.podcastDirectory + "/" + filelist[l] === episode.downloadedfile) {
391− isOrphanFile = false
392− }
393− }
394− }
395− }
379+ var rs2 = tx.executeSql("SELECT rowid FROM Episode WHERE downloadedfile = ?", [fileManager.podcastDirectory + "/" + filelist[l]])
396380
397− if (isOrphanFile) {
381+ if (rs2.rows.length == 0) {
398382 orphanListItem.fileCount++
399383 fileManager.deleteFile(fileManager.podcastDirectory + "/" + filelist[l])
400384 console.log("[LOG]: Removed Orphan File: " + fileManager.podcastDirectory + "/" + filelist[l])
401385 }
402386 }
403387
404− // Go through every podcast in the db and find orphaned links
405− for (i=0; i < rs.rows.length; i++) {
388+ // Filter all episode with downloadedfile links and check if they are orphaned links or not
389+ var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE downloadedfile IS NOT NULL")
390+ for (var i=0; i<rs2.rows.length; i++) {
406391 var isOrphanLink = true
407− podcast = rs.rows.item(i);
408− rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=?", [podcast.rowid]);
409−
410− // Go through every episode in the podcast
411− for (j=0; j < rs2.rows.length; j++) {
412− episode = rs2.rows.item(j);
413− if (episode.downloadedfile) {
414− for (l = 0; l < filelist.length; l++) {
415− if(episode.downloadedfile === fileManager.podcastDirectory + "/" + filelist[l]) {
416− isOrphanLink = false
417− }
418− }
392+ var episode = rs2.rows.item(i);
419393
420− if (isOrphanLink) {
421− orphanListItem.linkCount++
422− tx.executeSql("UPDATE Episode SET downloadedfile = NULL WHERE guid = ?", [episode.guid]);
423− console.log("[LOG]: Removed Orphan Link: " + episode.downloadedfile)
424− }
394+ for (var l = 0; l < filelist.length; l++) {
395+ if(episode.downloadedfile === fileManager.podcastDirectory + "/" + filelist[l]) {
396+ isOrphanLink = false
397+ break
425398 }
426399 }
400+
401+ if (isOrphanLink) {
402+ orphanListItem.linkCount++
403+ tx.executeSql("UPDATE Episode SET downloadedfile = NULL WHERE guid = ?", [episode.guid]);
404+ console.log("[LOG]: Removed Orphan Link: " + episode.downloadedfile)
405+ }
427406 }
428407 });
429408 }