diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-24 18:11:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-24 18:47:29 +0100 |
commit | 7323709537c6ff14136cd79fb07606cd79391758 (patch) | |
tree | 3d817d449d4c0a821b9b5073c8acf826c6ccfda1 /base/src/temp.rs | |
parent | cbb2e163abfefd8ed61c41a096d5d6c27b4721b4 (diff) | |
download | jellything-7323709537c6ff14136cd79fb07606cd79391758.tar jellything-7323709537c6ff14136cd79fb07606cd79391758.tar.bz2 jellything-7323709537c6ff14136cd79fb07606cd79391758.tar.zst |
refactor asset system pt. 1
Diffstat (limited to 'base/src/temp.rs')
-rw-r--r-- | base/src/temp.rs | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/base/src/temp.rs b/base/src/temp.rs deleted file mode 100644 index ee44004..0000000 --- a/base/src/temp.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2023 metamuffin <metamuffin.org> -*/ -use crate::AssetLocationExt; -use anyhow::Context; -use jellycommon::AssetLocation; -use std::{fs::File, sync::atomic::AtomicUsize}; - -static TEMP_COUNTER: AtomicUsize = AtomicUsize::new(0); - -pub struct TempFile(pub AssetLocation); - -impl TempFile { - pub fn new(generate: impl FnOnce(File) -> anyhow::Result<()>) -> anyhow::Result<Self> { - let i = TEMP_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - let loc = AssetLocation::Temp(format!("jellything-temp-{i}").into()); - - let file = File::create(loc.path()).context("creating temp file")?; - generate(file).context("tempfile generation")?; - - Ok(Self(loc)) - } -} -impl Drop for TempFile { - fn drop(&mut self) { - std::fs::remove_file(self.0.path()).expect("cant unlink tempfile") - } -} |