Esempio n. 1
0
static void AugmentMountInfo(Rlist **list, char *host, char *source, char *mounton, char *options)
{
    Mount *entry = xcalloc(1, sizeof(Mount));

    if (host)
    {
        entry->host = xstrdup(host);
    }

    if (source)
    {
        entry->source = xstrdup(source);
    }

    if (mounton)
    {
        entry->mounton = xstrdup(mounton);
    }

    if (options)
    {
        entry->options = xstrdup(options);
    }

    AppendRlistAlien(list, (void *) entry);
}
Esempio n. 2
0
static void PopulateAvailable(const char *arg)
{
    Package *p = DeserializePackage(arg);
    PackagePattern *pattern = MatchSame(p);

    if (FindPackages(AVAILABLE_PACKAGES_FILE_NAME, pattern) != NULL)
    {
        fprintf(stderr, "Skipping already available package %s\n", SerializePackage(p));
        return;
    }

    Rlist *available_packages = ReadPackageEntries(AVAILABLE_PACKAGES_FILE_NAME);

    AppendRlistAlien(&available_packages, p);
    SavePackages(AVAILABLE_PACKAGES_FILE_NAME, available_packages);
}
Esempio n. 3
0
static Rlist *FindPackages(const char *database_filename, PackagePattern *pattern)
{
    Rlist *db = ReadPackageEntries(database_filename);
    Rlist *matching = NULL;

    Rlist *rp = NULL;

    for (rp = db; rp != NULL; rp = rp->next)
    {
        Package *package = (Package *) rp->item;

        if (MatchPackage(pattern, package))
        {
            AppendRlistAlien(&matching, package);
        }
    }

    return matching;
}
Esempio n. 4
0
static Rlist *ReadPackageEntries(const char *database_filename)
{
    FILE *packages_file = fopen(database_filename, "r");
    Rlist *packages = NULL;

    if (packages_file != NULL)
    {
        char serialized_package[MAX_PACKAGE_ENTRY_LENGTH];

        while (fscanf(packages_file, "%s\n", serialized_package) != EOF)
        {
            Package *package = DeserializePackage(serialized_package);

            AppendRlistAlien(&packages, package);
        }

        fclose(packages_file);
    }

    return packages;
}
Esempio n. 5
0
static void AddPackage(PackagePattern *pattern)
{
    fprintf(stderr, "Trying to install all packages matching pattern %s\n", SerializePackagePattern(pattern));

    Rlist *matching_available = FindPackages(AVAILABLE_PACKAGES_FILE_NAME, pattern);

    if (matching_available == NULL)
    {
        fprintf(stderr, "Unable to find any package matching %s\n", SerializePackagePattern(pattern));
        exit(1);
    }

    Rlist *rp;

    for (rp = matching_available; rp; rp = rp->next)
    {
        Package *p = (Package *) rp->item;

        PackagePattern *pat = MatchAllVersions((Package *) rp->item);

        if (FindPackages(INSTALLED_PACKAGES_FILE_NAME, pat) != NULL)
        {
            fprintf(stderr, "Package %s is already installed.\n", SerializePackage(p));
            exit(1);
        }
    }

    Rlist *installed_packages = ReadPackageEntries(INSTALLED_PACKAGES_FILE_NAME);

    for (rp = matching_available; rp; rp = rp->next)
    {
        Package *p = (Package *) rp->item;

        AppendRlistAlien(&installed_packages, p);
        fprintf(stderr, "Succesfully installed package %s\n", SerializePackage(p));
    }

    SavePackages(INSTALLED_PACKAGES_FILE_NAME, installed_packages);
    exit(0);
}