10 static const char *guess_repo_name(const char *path);
11 static int parse_args(int argc, char **argv);
13 static const char *repo_path, *repo_name;
15 int main(int argc, char **argv)
17 if(parse_args(argc, argv) == -1) {
21 if(repo_init(repo_path) == -1) {
27 if(!(repo_name = guess_repo_name(repo_path))) {
32 printf("Serving %s from %s\n", repo_name, repo_path);
37 int i, count = repo_num_files();
38 for(i=0; i<count; i++) {
39 struct repo_file *file = repo_file(i);
40 memcpy(sum.sum, file->chksum, sizeof sum.sum);
41 printf("%s\tmd5:%s size:%lu mtime:%s", file->path, md5_sumstr(&sum),
42 (unsigned long)file->size, ctime(&file->mtime));
49 static const char *guess_repo_name(const char *path)
51 static char pathbuf[PATH_MAX];
55 if(!realpath(path, pathbuf)) {
58 len = strlen(pathbuf);
60 if(len > 0 && pathbuf[len - 1] == '/') {
63 if(len <= 0) goto fail;
65 if((last_slash = strrchr(pathbuf, '/'))) {
66 return last_slash + 1;
71 fprintf(stderr, "failed to resolve path %s while determining the repo name. Please specify an explicit name with -id\n", repo_path);
75 static void print_usage(const char *argv0)
77 printf("Usage: %s [options] [repo path]\n", argv0);
79 printf(" -id <name>: repo identifier (defaults to directory name)\n");
80 printf(" -h,-help: print help and exit\n");
83 static int parse_args(int argc, char **argv)
87 for(i=1; i<argc; i++) {
88 if(argv[i][0] == '-') {
89 if(strcmp(argv[i], "-id") == 0) {
90 repo_name = argv[++i];
91 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
95 fprintf(stderr, "invalid option: %s\n", argv[i]);
100 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
107 if(!repo_path) repo_path = ".";