| git.druid.rocks | index | druid520 | mp | src/ | stage.c |
src/stage.c
#define _POSIX_C_SOURCE 200809L
#define _NETBSD_SOURCE 1
#include <stdio.h>
#include <sys/stat.h>
#include "mpx.h"
void
cmd_snapshot(int argc, char** argv)
{
FILE* out;
struct stat basest;
struct stat exst;
dev_t basedev;
int has_exclude = 0;
dev_t excldev = 0;
ino_t exclino = 0;
/* the optional 4th arg is the configured WD (staging area) -- see
* fstree.c's walktree for why it needs excluding, only relevant when
* it happens to live inside <prefix>. an exclude path that can't be
* lstat'd (doesn't exist, e.g. WD not yet created) is simply not
* excluded rather than failing the whole snapshot over it. */
if(argc != 4 && argc != 5)
{
badusage(argv[0], "snapshot <prefix> <outfile> [exclude]");
}
if(lstat(argv[2], &basest) != 0)
{
die("failed reading prefix");
}
basedev = basest.st_dev;
if(argc == 5 && argv[4][0] != '\0' && lstat(argv[4], &exst) == 0)
{
has_exclude = 1;
excldev = exst.st_dev;
exclino = exst.st_ino;
}
out = fopen(argv[3], "w");
if(out == NULL)
{
die("failed opening snapshot outfile");
}
walktree(argv[2], "", out, basedev, has_exclude, excldev, exclino);
fclose(out);
}
void
cmd_stage(int argc, char** argv)
{
if(argc != 4)
{
badusage(argv[0], "stage <portdir> <dest>");
}
if(!pathfits(argv[2], "/pkg.conf") || !pathfits(argv[3], "/pkg.conf"))
{
die("path too long");
}
copytree(argv[2], argv[3]);
}
void
cmd_unstage(int argc, char** argv)
{
if(argc != 3)
{
badusage(argv[0], "unstage <dest>");
}
rmtree(argv[2]);
}