CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
- Added pkginfo to .gitignore
[pkgutils-cross.git] / pkgutil.cc
index 00cedafab26c95ed795e96af8c4fd6d17196cc92..1bbb83d518fd7e49f0c3655ca76d5e18b3e6121f 100644 (file)
@@ -2,6 +2,7 @@
 //  pkgutils
 // 
 //  Copyright (c) 2000-2005 Per Liden
+//  Copyright (c) 2006-2013 by CRUX team (http://crux.nu)
 // 
 //  This program is free software; you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
 #include <archive_entry.h>
 
 #define INIT_ARCHIVE(ar) \
-       archive_read_support_compression_all((ar)); \
-       archive_read_support_format_all((ar))
+       archive_read_support_filter_gzip((ar)); \
+       archive_read_support_filter_bzip2((ar)); \
+       archive_read_support_filter_xz((ar)); \
+       archive_read_support_format_tar((ar))
+
+#define DEFAULT_BYTES_PER_BLOCK (20 * 512)
 
 using __gnu_cxx::stdio_filebuf;
 
@@ -349,8 +354,8 @@ pair<string, pkgutil::pkginfo_t> pkgutil::pkg_open(const string& filename) const
        INIT_ARCHIVE(archive);
 
        if (archive_read_open_filename(archive,
-           const_cast<char*>(filename.c_str()),
-           ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
+           filename.c_str(),
+           DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
                throw runtime_error_with_errno("could not open " + filename, archive_errno(archive));
 
        for (i = 0; archive_read_next_header(archive, &entry) ==
@@ -373,7 +378,7 @@ pair<string, pkgutil::pkginfo_t> pkgutil::pkg_open(const string& filename) const
                        throw runtime_error("could not read " + filename);
        }
 
-       archive_read_finish(archive);
+       archive_read_free(archive);
 
        return result;
 }
@@ -383,22 +388,25 @@ void pkgutil::pkg_install(const string& filename, const set<string>& keep_list,
        struct archive* archive;
        struct archive_entry* entry;
        unsigned int i;
+       char buf[PATH_MAX];
+       string absroot;
 
        archive = archive_read_new();
        INIT_ARCHIVE(archive);
 
        if (archive_read_open_filename(archive,
-           const_cast<char*>(filename.c_str()),
-           ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
+           filename.c_str(),
+           DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
                throw runtime_error_with_errno("could not open " + filename, archive_errno(archive));
 
        chdir(root.c_str());
+       absroot = getcwd(buf, sizeof(buf));
 
        for (i = 0; archive_read_next_header(archive, &entry) ==
             ARCHIVE_OK; ++i) {
                string archive_filename = archive_entry_pathname(entry);
-               string reject_dir = trim_filename(root + string("/") + string(PKG_REJECTED));
-               string original_filename = trim_filename(root + string("/") + archive_filename);
+               string reject_dir = trim_filename(absroot + string("/") + string(PKG_REJECTED));
+               string original_filename = trim_filename(absroot + string("/") + archive_filename);
                string real_filename = original_filename;
 
                // Check if file is filtered out via INSTALL
@@ -423,7 +431,7 @@ void pkgutil::pkg_install(const string& filename, const set<string>& keep_list,
                                           (real_filename.c_str()));
 
                // Extract file
-               unsigned int flags = ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_UNLINK;
+               unsigned int flags = ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_UNLINK;
 
                if (archive_read_extract(archive, entry, flags) != ARCHIVE_OK) {
                        // If a file fails to install we just print an error message and
@@ -461,7 +469,7 @@ void pkgutil::pkg_install(const string& filename, const set<string>& keep_list,
                        throw runtime_error("could not read " + filename);
        }
 
-       archive_read_finish(archive);
+       archive_read_free(archive);
 }
 
 void pkgutil::ldconfig() const
@@ -503,8 +511,8 @@ void pkgutil::pkg_footprint(string& filename) const
        INIT_ARCHIVE(archive);
 
        if (archive_read_open_filename(archive,
-           const_cast<char*>(filename.c_str()),
-           ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
+           filename.c_str(),
+           DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
                 throw runtime_error_with_errno("could not open " + filename, archive_errno(archive));
 
        for (i = 0; archive_read_next_header(archive, &entry) ==
@@ -522,7 +530,7 @@ void pkgutil::pkg_footprint(string& filename) const
                        throw runtime_error_with_errno("could not read " + filename, archive_errno(archive));
        }
 
-       archive_read_finish(archive);
+       archive_read_free(archive);
 
        // Too bad, there doesn't seem to be a way to reuse our archive
        // instance
@@ -530,8 +538,8 @@ void pkgutil::pkg_footprint(string& filename) const
        INIT_ARCHIVE(archive);
 
        if (archive_read_open_filename(archive,
-           const_cast<char*>(filename.c_str()),
-           ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
+           filename.c_str(),
+           DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
                 throw runtime_error_with_errno("could not open " + filename, archive_errno(archive));
 
        for (i = 0; archive_read_next_header(archive, &entry) ==
@@ -604,7 +612,7 @@ void pkgutil::pkg_footprint(string& filename) const
                        throw runtime_error("could not read " + filename);
        }
 
-       archive_read_finish(archive);
+       archive_read_free(archive);
 }
 
 void pkgutil::print_version() const