Skip to content

Commit 9ad5d73

Browse files
committed
add a test for modified_since and fix a bug with the db filesystem on sqlite
1 parent e455407 commit 9ad5d73

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

Cargo.lock

Lines changed: 38 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ panic = "abort"
1818
codegen-units = 2
1919

2020
[dependencies]
21-
sqlx = { package = "sqlx-oldapi", version = "0.6.36", features = [
21+
sqlx = { package = "sqlx-oldapi", version = "0.6.37", features = [
2222
"any",
2323
"runtime-actix-rustls",
2424
"sqlite",

src/filesystem.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,19 @@ impl DbFsQueries {
197197
path: &Path,
198198
since: DateTime<Utc>,
199199
) -> anyhow::Result<bool> {
200-
self.was_modified
200+
let query = self
201+
.was_modified
201202
.query_as::<(bool,)>()
202203
.bind(since)
203-
.bind(path.display().to_string())
204+
.bind(path.display().to_string());
205+
log::trace!(
206+
"Checking if file {path:?} was modified since {since} by executing query: \n\
207+
{}\n\
208+
with parameters: {:?}",
209+
self.was_modified.sql(),
210+
(since, path)
211+
);
212+
query
204213
.fetch_optional(&app_state.db.connection)
205214
.await
206215
.map(|modified| modified.is_some())
@@ -261,5 +270,27 @@ async fn test_sql_file_read_utf8() -> anyhow::Result<()> {
261270
.read_to_string(&state, "unit test file.txt".as_ref(), false)
262271
.await?;
263272
assert_eq!(actual, "Héllö world! 😀");
273+
274+
let one_hour_ago = Utc::now() - chrono::Duration::hours(1);
275+
let one_hour_future = Utc::now() + chrono::Duration::hours(1);
276+
277+
let was_modified = fs
278+
.modified_since(&state, "unit test file.txt".as_ref(), one_hour_ago, false)
279+
.await?;
280+
assert!(was_modified, "File should be modified since one hour ago");
281+
282+
let was_modified = fs
283+
.modified_since(
284+
&state,
285+
"unit test file.txt".as_ref(),
286+
one_hour_future,
287+
false,
288+
)
289+
.await?;
290+
assert!(
291+
!was_modified,
292+
"File should not be modified since one hour in the future"
293+
);
294+
264295
Ok(())
265296
}

0 commit comments

Comments
 (0)