From 313888954b7c2a7428783fd942439b6993e24052 Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Thu, 11 Jan 2024 18:24:51 +0530 Subject: [PATCH] Update Schema, Improve Code --- .changes/priority-and-section.md | 5 +++++ bindings/packager/nodejs/schema.json | 14 ++++++++++++++ crates/packager/schema.json | 14 ++++++++++++++ crates/packager/src/package/deb/mod.rs | 19 +++++++------------ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .changes/priority-and-section.md diff --git a/.changes/priority-and-section.md b/.changes/priority-and-section.md new file mode 100644 index 00000000..8243e5b5 --- /dev/null +++ b/.changes/priority-and-section.md @@ -0,0 +1,5 @@ +--- +"cargo-packager": minor +--- + +Add the support for priority and section in Debian Config diff --git a/bindings/packager/nodejs/schema.json b/bindings/packager/nodejs/schema.json index f8f48fad..43a412b7 100644 --- a/bindings/packager/nodejs/schema.json +++ b/bindings/packager/nodejs/schema.json @@ -722,6 +722,20 @@ "null" ] }, + "section": { + "description": "Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections", + "type": [ + "string", + "null" + ] + }, + "priority": { + "description": "Change the priority of the Debian Package. By default, it is set to optional. Recognized Priorities as of now are : required, important, standard, optional, extra", + "type": [ + "string", + "null" + ] + }, "files": { "description": "List of custom files to add to the deb package. Maps a dir/file to a dir/file inside the debian package.", "type": [ diff --git a/crates/packager/schema.json b/crates/packager/schema.json index f8f48fad..43a412b7 100644 --- a/crates/packager/schema.json +++ b/crates/packager/schema.json @@ -722,6 +722,20 @@ "null" ] }, + "section": { + "description": "Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections", + "type": [ + "string", + "null" + ] + }, + "priority": { + "description": "Change the priority of the Debian Package. By default, it is set to optional. Recognized Priorities as of now are : required, important, standard, optional, extra", + "type": [ + "string", + "null" + ] + }, "files": { "description": "List of custom files to add to the deb package. Maps a dir/file to a dir/file inside the debian package.", "type": [ diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index f3493520..dd17fcb3 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -10,6 +10,7 @@ use std::{ fs::File, io::Write, path::{Path, PathBuf}, + os::unix::fs::MetadataExt, }; use handlebars::Handlebars; @@ -18,6 +19,7 @@ use image::{codecs::png::PngDecoder, ImageDecoder}; use relative_path::PathExt; use serde::Serialize; use walkdir::WalkDir; +use tar::HeaderMode; use super::Context; use crate::{ @@ -426,22 +428,15 @@ fn create_tar_from_dir, W: Write>(src_dir: P, dest_file: W) -> cr continue; } let dest_path = src_path.strip_prefix(src_dir)?; + let stat = std::fs::metadata(src_path)?; + let mut header = tar::Header::new_gnu(); + header.set_metadata_in_mode(&stat, HeaderMode::Deterministic); + header.set_mtime(stat.mtime() as u64); + if entry.file_type().is_dir() { - let stat = std::fs::metadata(src_path)?; - let mut header = tar::Header::new_gnu(); - header.set_mode(0o755); - header.set_metadata(&stat); - header.set_uid(0); - header.set_gid(0); tar_builder.append_data(&mut header, dest_path, &mut std::io::empty())?; } else { let mut src_file = std::fs::File::open(src_path)?; - let stat = src_file.metadata()?; - let mut header = tar::Header::new_gnu(); - header.set_mode(0o644); - header.set_metadata(&stat); - header.set_uid(0); - header.set_gid(0); tar_builder.append_data(&mut header, dest_path, &mut src_file)?; } }