Skip to content

Commit 8667ac3

Browse files
committed
Include media filter to avoid looping over empty directories
1 parent 6bc64df commit 8667ac3

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![none-shall-pass][nsp-logo]][nsp]
99

1010
#### Summary
11-
[`ios`][repo] is a light weight CLI tool to extract iPhone backups.
11+
[`ios`][repo] is a lightweight CLI tool to extract iPhone backups.
1212

1313
### Installation
1414

src/dbutil.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use crate::squire;
12
use rusqlite::Connection;
23
use std::path::Path;
34

45
#[allow(dead_code)]
5-
fn get_columns(manifest_db_path: &Path) -> rusqlite::Result<(), Box<dyn std::error::Error>> {
6+
pub fn get_columns(manifest_db_path: &Path) -> rusqlite::Result<(), Box<dyn std::error::Error>> {
67
let conn = Connection::open(manifest_db_path)?;
78
let mut col_smt = conn.prepare("PRAGMA table_info(Files)")?;
89
let columns: Vec<String> = col_smt
@@ -19,15 +20,18 @@ fn get_columns(manifest_db_path: &Path) -> rusqlite::Result<(), Box<dyn std::err
1920
}
2021

2122
#[allow(dead_code)]
22-
fn get_table(
23+
pub fn get_table(
2324
manifest_db_path: &Path,
2425
limit: Option<usize>,
2526
) -> rusqlite::Result<(), Box<dyn std::error::Error>> {
2627
let conn = Connection::open(manifest_db_path)?;
27-
let statement = if limit.is_some() {
28-
format!("SELECT * FROM Files LIMIT {}", limit.unwrap())
29-
} else {
30-
"SELECT * FROM Files".to_string()
28+
let statement = match limit {
29+
Some(head) => format!(
30+
"SELECT * FROM Files {} LIMIT {}",
31+
squire::media_filter(),
32+
head
33+
),
34+
None => format!("SELECT * FROM Files {}", squire::media_filter()),
3135
};
3236
let mut col_smt = conn.prepare(&statement)?;
3337
let columns: Vec<String> = col_smt

src/fileio.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::constant;
21
use crate::parser;
2+
use crate::{constant, squire};
33
use plist::Value;
44
use rusqlite::{Connection, Result};
55
use std::fs::{create_dir_all, File};
@@ -57,13 +57,17 @@ pub fn parse_manifest_db(
5757
let conn = Connection::open(manifest_db_path)?;
5858

5959
// Get count to update progress bar
60-
let mut count_stmt = conn.prepare(
61-
"SELECT COUNT(*) FROM Files WHERE relativePath LIKE '%DCIM/%' OR relativePath LIKE '%PhotoData/%'"
62-
)?;
60+
let mut count_stmt = conn.prepare(&format!(
61+
"SELECT COUNT(*) FROM Files {}'",
62+
squire::media_filter()
63+
))?;
6364
let count: usize = count_stmt.query_row([], |row| row.get(0))?;
6465
let progress_bar_base: Arc<Mutex<Pbar>> = Arc::new(Mutex::new(pbar(Some(count))));
6566

66-
let mut stmt = conn.prepare("SELECT fileID, relativePath FROM Files WHERE relativePath LIKE '%DCIM/%' OR relativePath LIKE '%PhotoData/%'")?;
67+
let mut stmt = conn.prepare(&format!(
68+
"SELECT fileID, relativePath FROM Files {}'",
69+
squire::media_filter()
70+
))?;
6771
let rows = stmt.query_map([], |row| {
6872
let file_id: String = row.get(0)?;
6973
let relative_path: String = row.get(1)?;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pub mod backup;
66
/// Module to load the required structs
77
pub mod constant;
8+
pub mod dbutil;
89
/// Module to handle database operations
910
pub mod fileio;
1011
/// Module to construct a custom logger
@@ -13,7 +14,6 @@ pub mod logger;
1314
pub mod parser;
1415
/// Module for helper functions
1516
pub mod squire;
16-
mod dbutil;
1717

1818
use rusqlite::Result;
1919

src/squire.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,30 @@ pub fn get_epoch() -> u64 {
153153
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
154154
}
155155
}
156+
157+
pub fn media_filter() -> String {
158+
"WHERE lower(relativePath) LIKE '%.hevc'
159+
OR lower(relativePath) LIKE '%.h264'
160+
OR lower(relativePath) LIKE '%.mp4'
161+
OR lower(relativePath) LIKE '%.m4v'
162+
OR lower(relativePath) LIKE '%.mov'
163+
OR lower(relativePath) LIKE '%.avi'
164+
OR lower(relativePath) LIKE '%.aac'
165+
OR lower(relativePath) LIKE '%.mp3'
166+
OR lower(relativePath) LIKE '%.m4a'
167+
OR lower(relativePath) LIKE '%.alac'
168+
OR lower(relativePath) LIKE '%.aiff'
169+
OR lower(relativePath) LIKE '%.wav'
170+
OR lower(relativePath) LIKE '%.flac'
171+
OR lower(relativePath) LIKE '%.ac3'
172+
OR lower(relativePath) LIKE '%.eac3'
173+
OR lower(relativePath) LIKE '%.heic'
174+
OR lower(relativePath) LIKE '%.jpg'
175+
OR lower(relativePath) LIKE '%.jpeg'
176+
OR lower(relativePath) LIKE '%.png'
177+
OR lower(relativePath) LIKE '%.gif'
178+
OR lower(relativePath) LIKE '%.tiff'
179+
OR lower(relativePath) LIKE '%.bmp'
180+
OR lower(relativePath) LIKE '%.ico';"
181+
.to_string()
182+
}

0 commit comments

Comments
 (0)