Skip to content

Commit

Permalink
set_archive_type function fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed May 26, 2024
1 parent c52c691 commit 9c949c8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 43 deletions.
8 changes: 0 additions & 8 deletions src/ccode.vala
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ public extern int sandbox_gid;
//DOC: daemonize current process
public extern void skeleton_daemon ();

#ifndef no_libarchive
//DOC: ### archive-create.c
//DOC: `void write_archive (string output,string[] files):`
//DOC: create archive file
//this functions and values used by util/archive.vala
public extern void write_archive (string output, string[] files);
public extern void set_archive_type (string filt, string form);
#endif
//DOC: ### file.c
//DOC: `int filesize (string path):`
//DOC: calculate file size
Expand Down
39 changes: 19 additions & 20 deletions src/ccode/archive-create.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _archive
#define _archive


#define zip 0
#define tar 1
#define p7zip 2
Expand All @@ -12,9 +11,6 @@
#define filter_gzip 1
#define filter_xz 2

int aformat = 1;
int afilter = 0;

#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#endif
Expand All @@ -34,6 +30,9 @@ int afilter = 0;

#include <limits.h>


#include <archive_extract.h>

#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
Expand Down Expand Up @@ -61,32 +60,32 @@ int has_error();
void error(int num);
#endif

void set_archive_type(char* form, char* filt){
void archive_set_type(archive *data, char* form, char* filt){
#ifdef debug
debug("Archive type changed");
debug(form);
debug(filt);
#endif
if(strcmp(form,"zip")==0)
aformat=zip;
data->aformat=zip;
else if(strcmp(form,"tar")==0)
aformat=tar;
data->aformat=tar;
else if(strcmp(form,"p7zip")==0)
aformat=p7zip;
data->aformat=p7zip;
else if(strcmp(form,"cpio")==0)
aformat=cpio;
data->aformat=cpio;
else if(strcmp(form,"ar")==0)
aformat=ar;
data->aformat=ar;

if(strcmp(filt,"none")==0)
afilter=filter_none;
data->afilter=filter_none;
else if(strcmp(filt,"gzip")==0)
afilter=filter_gzip;
data->afilter=filter_gzip;
else if(strcmp(filt,"xz")==0)
afilter=filter_xz;
data->afilter=filter_xz;
}

void write_archive(const char *outname, const char **filename) {
void archive_write(archive *data, const char *outname, const char **filename) {
struct archive *a;
struct archive_entry *entry;
struct stat st;
Expand All @@ -97,21 +96,21 @@ void write_archive(const char *outname, const char **filename) {

a = archive_write_new();
/* compress format */
if(afilter == filter_gzip){
if(data->afilter == filter_gzip){
archive_write_add_filter_gzip(a);
}else if(afilter == filter_xz){
}else if(data->afilter == filter_xz){
archive_write_add_filter_xz(a);
}else{
archive_write_add_filter_none(a);
}
/* archive format */
if(aformat == tar){
if(data->aformat == tar){
e = (archive_write_set_format_gnutar(a) != ARCHIVE_OK);
}else if (aformat == p7zip){
}else if (data->aformat == p7zip){
e = (archive_write_set_format_7zip(a) != ARCHIVE_OK);
}else if (aformat == cpio){
}else if (data->aformat == cpio){
e = (archive_write_set_format_cpio(a) != ARCHIVE_OK);
}else if (aformat == ar){
}else if (data->aformat == ar){
e = (archive_write_set_format_ar_bsd(a) != ARCHIVE_OK);
}else{
e = (archive_write_set_format_zip(a) != ARCHIVE_OK);
Expand Down
7 changes: 2 additions & 5 deletions src/ccode/archive-extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <archive.h>
#include <archive_entry.h>

extern void set_archive_type(char* type, char* algorthm);
extern void write_archive(char* path, char** add_list);

extern void error_add(char* message);

extern char* build_string(char* format, ...);
Expand Down Expand Up @@ -55,7 +52,7 @@ void archive_unref(archive *data){
void archive_load(archive *data, char* path) {
fdebug("archive load: %s", path);
data->archive_path = strdup(path);
set_archive_type("zip", "none");
archive_set_type(data, "zip", "none");
}

void archive_load_archive(archive *data) {
Expand Down Expand Up @@ -103,7 +100,7 @@ void archive_add(archive *data, char *path) {
void archive_create(archive *data){
fdebug("archive create: %s", data->archive_path);
int *len;
write_archive(data->archive_path, array_get(data->a, &len));
archive_write(data, data->archive_path, array_get(data->a, &len));
}

void archive_extract(archive *data, char *path) {
Expand Down
4 changes: 4 additions & 0 deletions src/include/archive_extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ typedef struct archive {
char *archive_path;
char *target_path;
int add_list_size;
int aformat;
int afilter;
array *a;
} archive;

Expand All @@ -23,6 +25,8 @@ void archive_add(archive* arch, char* path);
char* archive_readfile(archive* arch, char* path);
char** archive_list_files(archive* arch, int* len);
int archive_is_archive(archive* arch, char* path);
void archive_write(archive *data, const char *outname, const char **filename);
void archive_set_type(archive *data, char* form, char* filt);

#endif /* ARCHIVE_CREATE_H */

2 changes: 1 addition & 1 deletion src/operations/utility/compress.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
private static int compress_main (string[] args) {
var tar = new archive ();
tar.load (args[0]);
set_archive_type (get_value ("type"), get_value ("algorithm"));
tar.set_type (get_value ("type"), get_value ("algorithm"));
if (args.length > 1) {
foreach (string file in args[1:]) {
if (isdir (file)) {
Expand Down
12 changes: 6 additions & 6 deletions src/util/builder_target/ymp.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void build_target_ymp_init() {
}
tar.add(file);
}
set_archive_type("zip", "none");
tar.set_type("zip", "none");
tar.create();
cd(curdir);
return buildpath + "/source.zip";
Expand Down Expand Up @@ -222,17 +222,17 @@ public void build_target_ymp_init() {
var tar = new archive();
if (get_value("compress") == "none") {
tar.load(buildpath + "/output/data.tar");
set_archive_type("tar", "none");
tar.set_type("tar", "none");
} else if (get_value("compress") == "gzip") {
tar.load(buildpath + "/output/data.tar.gz");
set_archive_type("tar", "gzip");
tar.set_type("tar", "gzip");
} else if (get_value("compress") == "xz") {
tar.load(buildpath + "/output/data.tar.xz");
set_archive_type("tar", "xz");
tar.set_type("tar", "xz");
} else {
// Default format (gzip)
tar.load(buildpath + "/output/data.tar.gz");
set_archive_type("tar", "gzip");
tar.set_type("tar", "gzip");
}
int fnum = 0;
string curdir = pwd();
Expand Down Expand Up @@ -285,7 +285,7 @@ public void build_target_ymp_init() {
tar.add(path);
}
}
set_archive_type("zip", "none");
tar.set_type("zip", "none");
tar.create();
cd(curdir);
return buildpath + "/package.zip";
Expand Down
6 changes: 3 additions & 3 deletions src/util/debian.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int deb_create (string fpath, string output) {
}
// update md5sums
writefile (path + "/DEBIAN/md5sums", md5sum_data);
set_archive_type ("tar", "xz");
data.set_type ("tar", "xz");
data.create ();
// create control.tar.xz
cd (path + "/DEBIAN");
Expand All @@ -57,7 +57,7 @@ public int deb_create (string fpath, string output) {
foreach (string file in listdir (".")) {
control.add (file);
}
set_archive_type ("tar", "xz");
control.set_type ("tar", "xz");
control.create ();
writefile (output + "/debian-binary", "2.0\n");
cd (output);
Expand All @@ -68,7 +68,7 @@ public int deb_create (string fpath, string output) {
debfile.add ("debian-binary");
debfile.add ("control.tar.xz");
debfile.add ("data.tar.xz");
set_archive_type ("ar", "none");
debfile.set_type ("ar", "none");
debfile.create ();
remove_file ("debian-binary");
remove_file ("control.tar.xz");
Expand Down
1 change: 1 addition & 0 deletions src/vapi/archive.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public class archive {
public string readfile(string path);
public string[] list_files();
public bool is_archive(string path);
public void set_type(string aformat, string afilt);
}

0 comments on commit 9c949c8

Please sign in to comment.