Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
2016-04-10 09:19:12 -04:00
|
|
|
* Copyright (c) 2013, 2015, 2016 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* tix-install.c
|
|
|
|
* Install a tix into a tix collection.
|
|
|
|
*/
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2016-08-09 19:29:04 -04:00
|
|
|
#include <err.h>
|
2013-03-26 07:40:43 -04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
2014-01-20 12:30:13 -05:00
|
|
|
#include <signal.h>
|
2013-03-26 07:40:43 -04:00
|
|
|
#include <stdarg.h>
|
2016-02-28 18:10:59 -05:00
|
|
|
#include <stdbool.h>
|
2013-03-26 07:40:43 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
void TipTixCollection(const char* prefix)
|
|
|
|
{
|
2016-08-09 19:29:04 -04:00
|
|
|
warnx("error: `%s' isn't a tix collection, use \"tix-collection %s "
|
|
|
|
"create\" before " "installing packages.", prefix, prefix);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyTixCollection(const char* prefix)
|
|
|
|
{
|
|
|
|
if ( !IsDirectory(prefix) )
|
|
|
|
{
|
|
|
|
if ( errno == ENOENT )
|
|
|
|
TipTixCollection(prefix);
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "error: tix collection unavailable: `%s'", prefix);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyTixDirectory(const char* prefix, const char* tix_dir)
|
|
|
|
{
|
|
|
|
if ( !IsDirectory(tix_dir) )
|
|
|
|
{
|
|
|
|
if ( errno == ENOENT )
|
|
|
|
TipTixCollection(prefix);
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "error: tix database unavailable: `%s'", tix_dir);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyTixDatabase(const char* prefix,
|
2015-01-22 18:07:40 -05:00
|
|
|
const char* tixdb_path)
|
2013-03-26 07:40:43 -04:00
|
|
|
{
|
|
|
|
if ( !IsDirectory(tixdb_path) )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "error: tix database unavailable: `%s'", tixdb_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
char* info_path = join_paths(tixdb_path, "collection.conf");
|
|
|
|
if ( !IsFile(info_path) )
|
|
|
|
{
|
|
|
|
if ( errno == ENOENT )
|
|
|
|
TipTixCollection(prefix);
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "error: tix collection information unavailable: `%s'",
|
|
|
|
info_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
char* installed_list_path = join_paths(tixdb_path, "installed.list");
|
|
|
|
FILE* installed_list_fp = fopen(installed_list_path, "a");
|
|
|
|
if ( !installed_list_fp )
|
|
|
|
{
|
2016-08-09 19:29:04 -04:00
|
|
|
warn("error: unable to open `%s' for writing",
|
|
|
|
installed_list_path);
|
|
|
|
errx(1, "error: `%s': do you have sufficient permissions to "
|
|
|
|
"administer this tix collection?", prefix);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
fclose(installed_list_fp);
|
|
|
|
free(installed_list_path);
|
|
|
|
free(info_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPackageInstalled(const char* tixdb_path, const char* package)
|
|
|
|
{
|
|
|
|
char* installed_list_path = join_paths(tixdb_path, "installed.list");
|
|
|
|
FILE* installed_list_fp = fopen(installed_list_path, "r");
|
|
|
|
if ( !installed_list_fp )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "`%s'", installed_list_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
char* line = NULL;
|
2015-08-29 15:34:06 -04:00
|
|
|
size_t line_size = 0;
|
2013-03-26 07:40:43 -04:00
|
|
|
ssize_t line_len;
|
|
|
|
while ( 0 < (line_len = getline(&line, &line_size, installed_list_fp)) )
|
|
|
|
{
|
2016-05-15 10:32:38 -04:00
|
|
|
if ( line[line_len-1] == '\n' )
|
2013-03-26 07:40:43 -04:00
|
|
|
line[--line_len] = '\0';
|
|
|
|
if ( !strcmp(line, package) )
|
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(line);
|
2016-05-15 10:32:38 -04:00
|
|
|
if ( ferror(installed_list_fp) )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "`%s'", installed_list_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
fclose(installed_list_fp);
|
|
|
|
free(installed_list_path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkPackageAsInstalled(const char* tixdb_path, const char* package)
|
|
|
|
{
|
|
|
|
char* installed_list_path = join_paths(tixdb_path, "installed.list");
|
|
|
|
FILE* installed_list_fp = fopen(installed_list_path, "a");
|
|
|
|
if ( !installed_list_fp )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "`%s'", installed_list_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
fprintf(installed_list_fp, "%s\n", package);
|
|
|
|
fflush(installed_list_fp);
|
|
|
|
|
|
|
|
if ( ferror(installed_list_fp) || fclose(installed_list_fp) == EOF )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "`%s'", installed_list_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
free(installed_list_path);
|
|
|
|
}
|
|
|
|
|
2015-07-29 19:08:49 -04:00
|
|
|
static void help(FILE* fp, const char* argv0)
|
2013-03-26 07:40:43 -04:00
|
|
|
{
|
2015-08-29 15:34:06 -04:00
|
|
|
fprintf(fp, "Usage: %s [OPTION]... [--collection=PREFIX] PACKAGE...\n", argv0);
|
2013-03-26 07:40:43 -04:00
|
|
|
fprintf(fp, "Install a tix into a tix collection.\n");
|
|
|
|
}
|
|
|
|
|
2015-07-29 19:08:49 -04:00
|
|
|
static void version(FILE* fp, const char* argv0)
|
2013-03-26 07:40:43 -04:00
|
|
|
{
|
2015-07-29 19:08:49 -04:00
|
|
|
fprintf(fp, "%s (Sortix) %s\n", argv0, VERSIONSTR);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
static char* collection = NULL;
|
|
|
|
static bool reinstall = false;
|
2017-04-10 10:03:36 -04:00
|
|
|
static bool quiet = false;
|
2015-08-29 15:34:06 -04:00
|
|
|
static char* tix_directory_path = NULL;
|
2016-04-10 09:19:12 -04:00
|
|
|
static int generation;
|
|
|
|
static const char* coll_prefix;
|
|
|
|
static const char* coll_platform;
|
2015-08-29 15:34:06 -04:00
|
|
|
|
|
|
|
void InstallPackage(const char* tix_path);
|
|
|
|
|
2013-03-26 07:40:43 -04:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2015-08-29 15:34:06 -04:00
|
|
|
collection = strdup("/");
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
const char* argv0 = argv[0];
|
|
|
|
for ( int i = 0; i < argc; i++ )
|
|
|
|
{
|
|
|
|
const char* arg = argv[i];
|
2015-07-29 19:08:49 -04:00
|
|
|
if ( arg[0] != '-' || !arg[1] )
|
2013-03-26 07:40:43 -04:00
|
|
|
continue;
|
|
|
|
argv[i] = NULL;
|
|
|
|
if ( !strcmp(arg, "--") )
|
|
|
|
break;
|
|
|
|
if ( arg[1] != '-' )
|
|
|
|
{
|
2016-02-28 18:10:59 -05:00
|
|
|
char c;
|
|
|
|
while ( (c = *++arg) ) switch ( c )
|
2013-03-26 07:40:43 -04:00
|
|
|
{
|
2017-04-10 10:03:36 -04:00
|
|
|
case 'q': quiet = true; break;
|
2013-03-26 07:40:43 -04:00
|
|
|
default:
|
2015-07-29 19:08:49 -04:00
|
|
|
fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c);
|
|
|
|
help(stderr, argv0);
|
2013-03-26 07:40:43 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2015-07-29 19:08:49 -04:00
|
|
|
else if ( !strcmp(arg, "--help") )
|
|
|
|
help(stdout, argv0), exit(0);
|
|
|
|
else if ( !strcmp(arg, "--version") )
|
|
|
|
version(stdout, argv0), exit(0);
|
2013-03-26 07:40:43 -04:00
|
|
|
else if ( GET_OPTION_VARIABLE("--collection", &collection) ) { }
|
2015-07-29 19:08:49 -04:00
|
|
|
else if ( !strcmp(arg, "--reinstall") )
|
|
|
|
reinstall = true;
|
2017-04-10 10:03:36 -04:00
|
|
|
else if ( !strcmp(arg, "--quiet") )
|
|
|
|
quiet = true;
|
2013-03-26 07:40:43 -04:00
|
|
|
else
|
|
|
|
{
|
2015-07-29 19:08:49 -04:00
|
|
|
fprintf(stderr, "%s: unknown option: %s\n", argv0, arg);
|
|
|
|
help(stderr, argv0);
|
2013-03-26 07:40:43 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( argc == 1 )
|
|
|
|
{
|
2015-07-29 19:08:49 -04:00
|
|
|
help(stdout, argv0);
|
2013-03-26 07:40:43 -04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2015-07-29 19:08:49 -04:00
|
|
|
compact_arguments(&argc, &argv);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
if ( argc <= 1 )
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: no package specified\n", argv0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
if ( !*collection )
|
2013-03-26 07:40:43 -04:00
|
|
|
{
|
2015-08-29 15:34:06 -04:00
|
|
|
free(collection);
|
|
|
|
collection = strdup("/");
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
VerifyTixCollection(collection);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
tix_directory_path = join_paths(collection, "tix");
|
|
|
|
VerifyTixDirectory(collection, tix_directory_path);
|
2016-04-10 09:19:12 -04:00
|
|
|
VerifyTixDatabase(collection, tix_directory_path);
|
|
|
|
|
|
|
|
char* coll_conf_path = join_paths(tix_directory_path, "collection.conf");
|
|
|
|
string_array_t coll_conf = string_array_make();
|
|
|
|
if ( !dictionary_append_file_path(&coll_conf, coll_conf_path) )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "`%s'", coll_conf_path);
|
2016-04-10 09:19:12 -04:00
|
|
|
VerifyTixCollectionConfiguration(&coll_conf, coll_conf_path);
|
|
|
|
free(coll_conf_path);
|
|
|
|
|
|
|
|
const char* coll_generation = dictionary_get(&coll_conf, "collection.generation");
|
|
|
|
assert(coll_generation);
|
|
|
|
generation = atoi(coll_generation);
|
|
|
|
coll_prefix = dictionary_get(&coll_conf, "collection.prefix");
|
|
|
|
assert(coll_prefix);
|
|
|
|
coll_platform = dictionary_get(&coll_conf, "collection.platform");
|
|
|
|
assert(coll_platform);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
for ( int i = 1; i < argc; i++ )
|
|
|
|
InstallPackage(argv[i]);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
2016-04-10 09:19:12 -04:00
|
|
|
string_array_reset(&coll_conf);
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
free(tix_directory_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-03-26 07:40:43 -04:00
|
|
|
|
2015-09-09 13:26:50 -04:00
|
|
|
static int strcmp_indirect(const void* a_ptr, const void* b_ptr)
|
|
|
|
{
|
|
|
|
const char* a = *(const char* const*) a_ptr;
|
|
|
|
const char* b = *(const char* const*) b_ptr;
|
|
|
|
return strcmp(a, b);
|
|
|
|
}
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
void InstallPackage(const char* tix_path)
|
|
|
|
{
|
2013-03-26 07:40:43 -04:00
|
|
|
if ( !IsFile(tix_path) )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "`%s'", tix_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
const char* tixinfo_path = "tix/tixinfo";
|
2015-08-29 15:34:06 -04:00
|
|
|
if ( !TarContainsFile(tix_path, tixinfo_path) )
|
2016-08-09 19:29:04 -04:00
|
|
|
errx(1, "`%s' doesn't contain a `%s' file", tix_path, tixinfo_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
string_array_t tixinfo = string_array_make();
|
2015-08-29 15:34:06 -04:00
|
|
|
FILE* tixinfo_fp = TarOpenFile(tix_path, tixinfo_path);
|
2013-03-26 07:40:43 -04:00
|
|
|
dictionary_append_file(&tixinfo, tixinfo_fp);
|
|
|
|
fclose(tixinfo_fp);
|
|
|
|
|
|
|
|
const char* package_name = dictionary_get(&tixinfo, "pkg.name");
|
|
|
|
assert(package_name);
|
|
|
|
|
|
|
|
const char* package_prefix = dictionary_get(&tixinfo, "pkg.prefix");
|
2015-08-29 15:34:06 -04:00
|
|
|
assert(package_prefix || !package_prefix);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
const char* package_platform = dictionary_get(&tixinfo, "tix.platform");
|
2015-08-29 15:34:06 -04:00
|
|
|
assert(package_platform || !package_platform);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
2016-04-10 09:19:12 -04:00
|
|
|
bool already_installed = IsPackageInstalled(tix_directory_path, package_name);
|
2013-03-26 07:40:43 -04:00
|
|
|
if ( already_installed && !reinstall )
|
2016-08-09 19:29:04 -04:00
|
|
|
errx(1, "error: package `%s' is already installed. Use --reinstall "
|
|
|
|
"to force reinstallation.", package_name);
|
2013-03-26 07:40:43 -04:00
|
|
|
|
|
|
|
if ( package_prefix && strcmp(coll_prefix, package_prefix) != 0 )
|
|
|
|
{
|
2016-08-09 19:29:04 -04:00
|
|
|
warn("error: `%s' is compiled with the prefix `%s', but the "
|
|
|
|
"destination collection has the prefix `%s'.", tix_path,
|
|
|
|
package_prefix, coll_prefix);
|
|
|
|
err(1, "you need to recompile the package with "
|
2013-03-26 07:40:43 -04:00
|
|
|
"--prefix=\"%s\".", coll_prefix);
|
|
|
|
}
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
if ( package_platform && strcmp(coll_platform, package_platform) != 0 )
|
2013-03-26 07:40:43 -04:00
|
|
|
{
|
2016-08-09 19:29:04 -04:00
|
|
|
warn("error: `%s' is compiled with the platform `%s', but "
|
2013-03-26 07:40:43 -04:00
|
|
|
"the destination collection has the platform `%s'.",
|
|
|
|
tix_path, package_platform, coll_platform);
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "you need to recompile the package with "
|
|
|
|
"--host=%s\".", coll_platform);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
|
2017-04-10 10:03:36 -04:00
|
|
|
if ( !quiet )
|
|
|
|
printf("Installing `%s' into `%s'...\n", package_name, collection);
|
|
|
|
|
2015-08-29 15:34:06 -04:00
|
|
|
char* data_and_prefix = package_prefix && package_prefix[0] ?
|
2013-03-26 07:40:43 -04:00
|
|
|
print_string("data%s", package_prefix) :
|
|
|
|
strdup("data");
|
2015-09-09 13:26:50 -04:00
|
|
|
|
2016-04-10 09:19:12 -04:00
|
|
|
char* tixinfo_out_path = print_string("%s/tixinfo/%s", tix_directory_path, package_name);
|
|
|
|
int tixinfo_fd = open(tixinfo_out_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
|
|
if ( tixinfo_fd < 0 )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "%s", tixinfo_out_path);
|
2016-04-10 09:19:12 -04:00
|
|
|
TarExtractFileToFD(tix_path, "tix/tixinfo", tixinfo_fd);
|
|
|
|
close(tixinfo_fd);
|
|
|
|
|
|
|
|
FILE* index_fp = TarOpenIndex(tix_path);
|
|
|
|
string_array_t files = string_array_make();
|
|
|
|
string_array_append_file(&files, index_fp);
|
|
|
|
qsort(files.strings, files.length, sizeof(char*), strcmp_indirect);
|
|
|
|
char* manifest_path = print_string("%s/manifest/%s", tix_directory_path, package_name);
|
|
|
|
FILE* manifest_fp = fopen(manifest_path, "w");
|
|
|
|
if ( !manifest_fp )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "%s", manifest_path);
|
2016-04-10 09:19:12 -04:00
|
|
|
for ( size_t i = 0; i < files.length; i++ )
|
2015-09-09 13:26:50 -04:00
|
|
|
{
|
2016-04-10 09:19:12 -04:00
|
|
|
char* str = files.strings[i];
|
|
|
|
if ( strncmp(str, "data", strlen("data")) != 0 )
|
|
|
|
continue;
|
|
|
|
str += strlen("data");
|
|
|
|
if ( str[0] && str[0] != '/' )
|
|
|
|
continue;
|
|
|
|
size_t len = strlen(str);
|
|
|
|
while ( 2 <= len && str[len-1] == '/' )
|
|
|
|
str[--len] = '\0';
|
|
|
|
if ( fprintf(manifest_fp, "%s\n", str) < 0 )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "%s", manifest_path);
|
2015-09-09 13:26:50 -04:00
|
|
|
}
|
2016-04-10 09:19:12 -04:00
|
|
|
if ( ferror(manifest_fp) || fflush(manifest_fp) == EOF )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "%s", manifest_path);
|
2016-04-10 09:19:12 -04:00
|
|
|
fclose(manifest_fp);
|
|
|
|
string_array_reset(&files);
|
|
|
|
fclose(index_fp);
|
2015-09-09 13:26:50 -04:00
|
|
|
|
2013-03-26 07:40:43 -04:00
|
|
|
if ( fork_and_wait_or_death() )
|
|
|
|
{
|
|
|
|
size_t num_strips = count_tar_components(data_and_prefix);
|
|
|
|
const char* cmd_argv[] =
|
|
|
|
{
|
2015-08-29 15:34:06 -04:00
|
|
|
"tar",
|
2013-03-26 07:40:43 -04:00
|
|
|
print_string("--strip-components=%zu", num_strips),
|
2015-08-29 15:34:06 -04:00
|
|
|
"-C", collection,
|
2013-03-26 07:40:43 -04:00
|
|
|
"--extract",
|
|
|
|
"--file", tix_path,
|
2015-03-31 18:24:41 -04:00
|
|
|
"--keep-directory-symlink",
|
2016-03-26 07:41:08 -04:00
|
|
|
"--same-permissions",
|
|
|
|
"--no-same-owner",
|
2013-03-26 07:40:43 -04:00
|
|
|
data_and_prefix,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
execvp(cmd_argv[0], (char* const*) cmd_argv);
|
2016-08-09 19:29:04 -04:00
|
|
|
err(127, "%s", cmd_argv[0]);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|
|
|
|
free(data_and_prefix);
|
|
|
|
|
|
|
|
if ( !already_installed )
|
2016-04-10 09:19:12 -04:00
|
|
|
MarkPackageAsInstalled(tix_directory_path, package_name);
|
2015-08-29 15:34:06 -04:00
|
|
|
|
|
|
|
string_array_reset(&tixinfo);
|
2013-03-26 07:40:43 -04:00
|
|
|
}
|