diff --git a/ui-snapshot.c b/ui-snapshot.c
index cf8b0d8..eeb6fad 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -69,6 +69,7 @@ static int write_compressed_tar_archive(const char *hex,
cgit_open_filter(&f.base);
rv = write_tar_archive(hex, prefix);
cgit_close_filter(&f.base);
+ fprintf(stderr, "%s %s %p %d\n", hex, prefix, filter_argv, rv);
return rv;
}
@@ -161,9 +162,88 @@ const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f)
return BIT(f - &cgit_snapshot_formats[0]);
}
+int mkdir_recursive(char* path)
+{
+ char *p = path;
+ while (*p) {
+ if (*p == '/') {
+ *p = '\0';
+ if (mkdir(path, 0755) < 0) {
+ if (errno != EEXIST) {
+ fprintf(stderr, "[cgit] Error creating directory %s: %s (%d)\n",
+ path, strerror(errno), errno);
+ return -1;
+ }
+ }
+ *p = '/';
+ }
+ p++;
+ }
+ if (mkdir(path, 0755) < 0) {
+ if (errno != EEXIST) {
+ fprintf(stderr, "[cgit] Error creating directory %s: %s (%d)\n",
+ path, strerror(errno), errno);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+char *get_snapshot_disk_path()
+{
+ if (!ctx.cfg.snapshot.save_on_disk)
+ return NULL;
+
+ // return ctx.cfg.snapshot.save_on_disk_root_dir "/" "";
+ char *path = xstrfmt("%s/%s", ctx.cfg.snapshot.save_on_disk_root_dir, ctx.repo->path);
+ if (mkdir(path, 0755) < 0) {
+ fprintf(stderr, "[cgit] Error creating snapshot directory %s: %s (%d)\n",
+ path, strerror(errno), errno);
+ free(path);
+ return NULL;
+ }
+ return path;
+}
+
+bool print_cached_file()
+{
+ char* path = get_snapshot_disk_path();
+ if (!path)
+ return false;
+
+ fprintf(stderr, "[cgit] Checking for cached file %s\n", path);
+
+ if (stat(path, NULL) < 0) {
+ if (errno == ENOENT) {
+ free(path);
+ return false; // No cached file found
+ }
+ fprintf(stderr, "[cgit] Error accessing cache file %s: %s (%d)\n",
+ path, strerror(errno), errno);
+ free(path);
+ return false;
+ }
+}
+
+static int start_cache_file()
+{
+ // if (!ctx.cfg.snapshot.save_on_disk)
+ // return 0;
+ //
+ // char* path = get_snapshot_disk_path();
+ // if (!path)
+ // return -1;
+ //
+ // freopen("output.txt", "a+", stdout);
+}
+static void end_cache_file()
+{
+
+}
+
static int make_snapshot(const struct cgit_snapshot_format *format,
- const char *hex, const char *prefix,
- const char *filename)
+ const char *hex, const char *prefix,
+ const char *filename)
{
struct object_id oid;
@@ -181,8 +261,14 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
ctx.page.mimetype = xstrdup(format->mimetype);
ctx.page.filename = xstrdup(filename);
cgit_print_http_headers();
+
+ if (print_cached_file())
+ return 0;
+
+ start_cache_file();
init_archivers();
format->write_func(hex, prefix);
+ end_cache_file();
return 0;
}
|