In-progress commit of online cleaner.
[bluesky.git] / bluesky / log.c
index 89d4258..3fb9ef0 100644 (file)
@@ -413,6 +413,7 @@ BlueSkyCacheFile *bluesky_cachefile_lookup(BlueSkyFS *fs,
         g_mutex_lock(map->lock);
         map->cond = g_cond_new();
         map->filename = g_strdup(logname);
+        map->log_dir = clouddir;
         map->log_seq = log_seq;
         map->log = log;
         g_atomic_int_set(&map->mapcount, 0);
@@ -480,11 +481,16 @@ static void cloudlog_partial_fetch_start(BlueSkyCacheFile *cachefile,
 static void cloudlog_partial_fetch_complete(BlueSkyStoreAsync *async,
                                             BlueSkyCacheFile *cachefile)
 {
-    g_print("Partial fetch of %s from cloud complete, status = %d\n",
+    g_print("Fetch of %s from cloud complete, status = %d\n",
             async->key, async->result);
 
     g_mutex_lock(cachefile->lock);
     if (async->result >= 0) {
+        if (async->len == 0) {
+            g_print("Complete object was fetched.\n");
+            cachefile->complete = TRUE;
+        }
+
         /* Descrypt items fetched and write valid items out to the local log,
          * but only if they do not overlap existing objects.  This will protect
          * against an attack by the cloud provider where one valid object is
@@ -493,9 +499,11 @@ static void cloudlog_partial_fetch_complete(BlueSkyStoreAsync *async,
         BlueSkyRangeset *items = bluesky_rangeset_new();
         int fd = openat(cachefile->log->dirfd, cachefile->filename, O_WRONLY);
         if (fd >= 0) {
+            gboolean allow_unauth;
             async->data = bluesky_string_dup(async->data);
+            allow_unauth = cachefile->log_dir == BLUESKY_CLOUD_DIR_CLEANER;
             bluesky_cloudlog_decrypt(async->data->data, async->data->len,
-                                     cachefile->fs->keys, items);
+                                     cachefile->fs->keys, items, allow_unauth);
             uint64_t item_offset = 0;
             while (TRUE) {
                 const BlueSkyRangesetItem *item;