Skip to content

Commit

Permalink
Check if blob file exists before deleting it from fs (#636)
Browse files Browse the repository at this point in the history
* Check if blob file exists before deleting it from fs

* Add entry to CHANGELOG.md
  • Loading branch information
adzialocha committed Jun 26, 2024
1 parent e600232 commit 1adec6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support private network secured by pre-shared key [#635](https://github.com/p2panda/aquadoggo/pull/635)
- Support private network secured by pre-shared key [#635](https://github.com/p2panda/aquadoggo/pull/635)

### Changed

Expand All @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Handle connection ids greater than 9 in `Peer` impl of `Human` trait [#634](https://github.com/p2panda/aquadoggo/pull/634)
- Check if blob file exists before deleting it from fs [#636](https://github.com/p2panda/aquadoggo/pull/636)

## [0.7.4]

Expand Down
14 changes: 8 additions & 6 deletions aquadoggo/src/materializer/tasks/garbage_collection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

use tokio::fs::remove_file;
use tokio::fs::{remove_file, try_exists};

use log::debug;
use p2panda_rs::document::DocumentViewId;
Expand Down Expand Up @@ -138,12 +138,14 @@ pub async fn garbage_collection_task(context: Context, input: TaskInput) -> Task
// We now remove all deleted blob views from the filesystem.
if is_blob {
for view_id in deleted_views {
// Delete this blob view from the filesystem also.
// Delete this blob view from the filesystem also
let blob_view_path = context.config.blobs_base_path.join(view_id.to_string());
remove_file(blob_view_path.clone())
.await
.map_err(|err| TaskError::Critical(err.to_string()))?;
debug!("Deleted blob view from filesystem: {}", view_id);
if let Ok(true) = try_exists(&blob_view_path).await {
remove_file(blob_view_path)
.await
.map_err(|err| TaskError::Critical(err.to_string()))?;
debug!("Deleted blob view from filesystem: {}", view_id);
}
}
}

Expand Down

0 comments on commit 1adec6d

Please sign in to comment.