1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/openeuler-stratovirt

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
temp_cleaner.rs 2.2 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
zhouli57 Отправлено 3 лет назад 3136607
// Copyright (c) 2020 Huawei Technologies Co.,Ltd. All rights reserved.
//
// StratoVirt is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan
// PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
// http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
use std::fs;
use std::io::Write;
static mut GLOBAL_TEMP_CLEANER: Option<TempCleaner> = None;
/// This structure used to keep temporary file which was created by program, and would be deleted
/// when Vm exit.
pub struct TempCleaner {
/// Path of files that should be removed after exiting the vm.
paths: Vec<String>,
}
impl TempCleaner {
pub fn object_init() {
unsafe {
if GLOBAL_TEMP_CLEANER.is_none() {
GLOBAL_TEMP_CLEANER = Some(TempCleaner { paths: Vec::new() });
}
}
}
/// Add to be removed file path
pub fn add_path(path: String) {
unsafe {
if let Some(tmp) = GLOBAL_TEMP_CLEANER.as_mut() {
tmp.paths.push(path);
}
}
}
/// Clean the temporary files
pub fn clean() {
unsafe {
if let Some(tmp) = GLOBAL_TEMP_CLEANER.as_mut() {
while let Some(path) = tmp.paths.pop() {
if let Err(ref e) = fs::remove_file(&path) {
write!(
&mut std::io::stderr(),
"Failed to delete console / socket file:{} :{} \r\n",
&path,
e
)
.expect("Failed to write to stderr");
} else {
write!(
&mut std::io::stdout(),
"Delete file: {} successfully.\r\n",
&path
)
.expect("Failed to write to stdout");
}
}
}
}
}
}

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/openeuler-stratovirt.git
git@gitlife.ru:oschina-mirror/openeuler-stratovirt.git
oschina-mirror
openeuler-stratovirt
openeuler-stratovirt
v2.2.0-rc6