From 0466089316565432603884bdc5a667b3a2e0eb31 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 7 May 2021 12:45:44 +0200 Subject: [PATCH] move api related type/regx definition from backup_info.rs to src/api2/types/mod.rs --- src/api2/types/mod.rs | 24 +++++++++++++++++++- src/backup/backup_info.rs | 47 +++++++-------------------------------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 21b5eade..e42083f0 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -11,7 +11,6 @@ use crate::{ backup::{ CryptMode, Fingerprint, - BACKUP_ID_REGEX, DirEntryAttribute, CatalogEntryType, }, @@ -51,6 +50,17 @@ pub const FILENAME_FORMAT: ApiStringFormat = ApiStringFormat::VerifyFn(|name| { Ok(()) }); +macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9_][A-Za-z0-9._\-]*") } +macro_rules! BACKUP_TYPE_RE { () => (r"(?:host|vm|ct)") } +macro_rules! BACKUP_TIME_RE { + () => (r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z") +} +macro_rules! SNAPSHOT_PATH_REGEX_STR { + () => ( + concat!(r"(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), ")/(", BACKUP_TIME_RE!(), r")") + ); +} + macro_rules! DNS_LABEL { () => (r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") } macro_rules! DNS_NAME { () => (concat!(r"(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) } @@ -113,6 +123,18 @@ const_regex!{ pub UUID_REGEX = r"^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$"; + pub BACKUP_TYPE_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), r")$"); + + pub BACKUP_ID_REGEX = concat!(r"^", BACKUP_ID_RE!(), r"$"); + + pub BACKUP_DATE_REGEX = concat!(r"^", BACKUP_TIME_RE!() ,r"$"); + + pub GROUP_PATH_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), r")$"); + + pub SNAPSHOT_PATH_REGEX = concat!(r"^", SNAPSHOT_PATH_REGEX_STR!(), r"$"); + + pub BACKUP_FILE_REGEX = r"^.*\.([fd]idx|blob)$"; + pub DATASTORE_MAP_REGEX = concat!(r"(:?", PROXMOX_SAFE_ID_REGEX_STR!(), r"=)?", PROXMOX_SAFE_ID_REGEX_STR!()); pub TAPE_RESTORE_SNAPSHOT_REGEX = concat!(r"^", PROXMOX_SAFE_ID_REGEX_STR!(), r":", SNAPSHOT_PATH_REGEX_STR!(), r"$"); diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index f39f2ed4..47e2db72 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -5,48 +5,17 @@ use std::os::unix::io::RawFd; use std::path::{Path, PathBuf}; -use proxmox::const_regex; +use crate::api2::types::{ + BACKUP_ID_REGEX, + BACKUP_TYPE_REGEX, + BACKUP_DATE_REGEX, + GROUP_PATH_REGEX, + SNAPSHOT_PATH_REGEX, + BACKUP_FILE_REGEX, +}; use super::manifest::MANIFEST_BLOB_NAME; -macro_rules! BACKUP_ID_RE { - () => { - r"[A-Za-z0-9_][A-Za-z0-9._\-]*" - }; -} -macro_rules! BACKUP_TYPE_RE { - () => { - r"(?:host|vm|ct)" - }; -} -macro_rules! BACKUP_TIME_RE { - () => { - r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z" - }; -} - -#[macro_export] -macro_rules! SNAPSHOT_PATH_REGEX_STR { - () => ( - concat!(r"(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), ")/(", BACKUP_TIME_RE!(), r")") - ); -} - -const_regex! { - BACKUP_FILE_REGEX = r"^.*\.([fd]idx|blob)$"; - - BACKUP_TYPE_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), r")$"); - - pub BACKUP_ID_REGEX = concat!(r"^", BACKUP_ID_RE!(), r"$"); - - BACKUP_DATE_REGEX = concat!(r"^", BACKUP_TIME_RE!() ,r"$"); - - GROUP_PATH_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), r")$"); - - SNAPSHOT_PATH_REGEX = concat!( - r"^", SNAPSHOT_PATH_REGEX_STR!(), r"$"); -} - /// BackupGroup is a directory containing a list of BackupDir #[derive(Debug, Eq, PartialEq, Hash, Clone)] pub struct BackupGroup {