From 32ffcdf2020a1d4962500c0855102644551e490e Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 31 Aug 2022 18:17:13 -0400 Subject: [PATCH] Added functionality to clean up transcoded source files --- src/repository.rs | 12 +++++++++--- src/transcoder.rs | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/repository.rs b/src/repository.rs index d532bb6..e02cc57 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -47,9 +47,9 @@ impl Repository { return ingest_files; } - pub fn archive_file(&self, file: String) { - let ingest_file = Path::new(&self.ingest_dir).join(&file); - let archive_file = Path::new(&self.archive_dir).join(&file); + pub fn archive_file(&self, file: &str) { + let ingest_file = Path::new(&self.ingest_dir).join(file); + let archive_file = Path::new(&self.archive_dir).join(file); match fs::copy(&ingest_file, &archive_file) { Ok(_) => { @@ -61,6 +61,12 @@ impl Repository { } } } + + pub fn cleanup_file(&self, file: &str) { + let ingest_file = Path::new(&self.ingest_dir).join(file); + fs::remove_file(&ingest_file) + .expect("File deletion failed."); + } } fn create_directory(path: &str) { diff --git a/src/transcoder.rs b/src/transcoder.rs index d1bb221..a6396e8 100644 --- a/src/transcoder.rs +++ b/src/transcoder.rs @@ -22,7 +22,13 @@ impl Transcoder { for i in ingest_files { // copy the file to the archive - self.repository.archive_file(i); + self.repository.archive_file(&i); + + // perform the video transcode + // TODO - self.transcode(i); + + // remove the source file + self.repository.cleanup_file(&i); } } }