feat: retrun latest archive in tar()
This commit is contained in:
parent
593f3d5c17
commit
f78a331e9c
5 changed files with 75 additions and 5 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -920,6 +920,18 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "filetime"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "firestorm"
|
name = "firestorm"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -2054,6 +2066,7 @@ dependencies = [
|
||||||
"mktemp",
|
"mktemp",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
|
"tar",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
|
@ -2860,6 +2873,17 @@ dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tar"
|
||||||
|
version = "0.4.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6"
|
||||||
|
dependencies = [
|
||||||
|
"filetime",
|
||||||
|
"libc",
|
||||||
|
"xattr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.3.0"
|
version = "3.3.0"
|
||||||
|
@ -3667,6 +3691,15 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xattr"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yaml-rust"
|
name = "yaml-rust"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
@ -57,4 +58,7 @@ pub trait Federate: Sync + Send {
|
||||||
name: &str,
|
name: &str,
|
||||||
hostname: &str,
|
hostname: &str,
|
||||||
) -> Result<(), Self::Error>;
|
) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
|
/// publish results in tar ball
|
||||||
|
async fn tar(&self) -> Result<PathBuf, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ pub async fn adding_forge_works<'a, T: Federate>(
|
||||||
|
|
||||||
// add repository
|
// add repository
|
||||||
ff.create_repository(&add_repo_msg).await.unwrap();
|
ff.create_repository(&add_repo_msg).await.unwrap();
|
||||||
|
|
||||||
|
// tar()
|
||||||
|
ff.tar().await.unwrap();
|
||||||
|
|
||||||
// delete repository
|
// delete repository
|
||||||
ff.delete_repository(add_repo_msg.owner, add_repo_msg.name, add_repo_msg.hostname)
|
ff.delete_repository(add_repo_msg.owner, add_repo_msg.name, add_repo_msg.hostname)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -17,6 +17,7 @@ serde_yaml = "0.8.24"
|
||||||
tokio = { version = "1.18.2", features = ["fs"]}
|
tokio = { version = "1.18.2", features = ["fs"]}
|
||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
url = { version = "2.2.2", features = ["serde"] }
|
url = { version = "2.2.2", features = ["serde"] }
|
||||||
|
tar = "0.4.38"
|
||||||
|
|
||||||
[dependencies.db-core]
|
[dependencies.db-core]
|
||||||
path = "../../db/db-core"
|
path = "../../db/db-core"
|
||||||
|
|
|
@ -36,6 +36,8 @@ pub const INSTANCE_INFO_FILE: &str = "instance.yml";
|
||||||
pub const USER_INFO_FILE: &str = "user.yml";
|
pub const USER_INFO_FILE: &str = "user.yml";
|
||||||
pub const REPO_INFO_FILE: &str = "publiccode.yml";
|
pub const REPO_INFO_FILE: &str = "publiccode.yml";
|
||||||
|
|
||||||
|
pub const CONTENTS_DIR: &str = "uncompressed";
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PccFederate {
|
pub struct PccFederate {
|
||||||
pub base_dir: String,
|
pub base_dir: String,
|
||||||
|
@ -43,15 +45,21 @@ pub struct PccFederate {
|
||||||
|
|
||||||
impl PccFederate {
|
impl PccFederate {
|
||||||
pub async fn new(base_dir: String) -> FResult<Self> {
|
pub async fn new(base_dir: String) -> FResult<Self> {
|
||||||
let path = Path::new(&base_dir);
|
let x = Self { base_dir };
|
||||||
if !path.exists() {
|
x.get_content_path(true).await?;
|
||||||
fs::create_dir_all(&path).await?;
|
Ok(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_content_path(&self, create_dirs: bool) -> FResult<PathBuf> {
|
||||||
|
let path = Path::new(&self.base_dir).join(CONTENTS_DIR);
|
||||||
|
if create_dirs {
|
||||||
|
self.create_dir_if_not_exists(&path).await?;
|
||||||
}
|
}
|
||||||
Ok(Self { base_dir })
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_instance_path(&self, hostname: &str, create_dirs: bool) -> FResult<PathBuf> {
|
pub async fn get_instance_path(&self, hostname: &str, create_dirs: bool) -> FResult<PathBuf> {
|
||||||
let path = Path::new(&self.base_dir).join(hostname);
|
let path = self.get_content_path(false).await?.join(hostname);
|
||||||
if create_dirs {
|
if create_dirs {
|
||||||
self.create_dir_if_not_exists(&path).await?;
|
self.create_dir_if_not_exists(&path).await?;
|
||||||
}
|
}
|
||||||
|
@ -166,4 +174,24 @@ impl Federate for PccFederate {
|
||||||
let path = self.get_repo_path(name, owner, hostname, false).await?;
|
let path = self.get_repo_path(name, owner, hostname, false).await?;
|
||||||
self.rm_util(&path).await
|
self.rm_util(&path).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn tar(&self) -> Result<PathBuf, Self::Error> {
|
||||||
|
use std::fs::File;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use tar::Builder;
|
||||||
|
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
let path = Path::new(&self.base_dir).join(format!("{now}.tar"));
|
||||||
|
let file = File::create(&path)?;
|
||||||
|
let mut a = Builder::new(file);
|
||||||
|
a.append_dir_all(".", self.get_content_path(false).await?)
|
||||||
|
.unwrap();
|
||||||
|
a.finish().unwrap();
|
||||||
|
Ok(path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue