LRN: two directory patches change the way "is_directory" is evaluated.
authorChristian Grothoff <christian@grothoff.org>
Wed, 22 Feb 2012 18:34:29 +0000 (18:34 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 22 Feb 2012 18:34:29 +0000 (18:34 +0000)
Now it must be GNUNET_YES for the execution flow to switch to a branch
where something is considered to be a directory.
The reason for that is that some functions might return GNUNET_SYSERR
when asked whether something is a directory or not. Checking this
value as "!= GNUNET_NO" will produce positive result, even though it's
not a directory.

src/fs/fs_api.c
src/fs/fs_dirmetascan.c
src/fs/fs_file_information.c
src/fs/fs_publish.c
src/fs/fs_sharetree.c
src/fs/gnunet-helper-fs-publish.c
src/fs/gnunet-publish.c

index 67be447f6704b7a80c43da633de396ea5eaa5016..1df9b2e0ac3a730bb7f151c3b014b326c26fa3c5 100644 (file)
@@ -1210,7 +1210,7 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
   {
     if (0 == strcmp (srch, pos->serialization))
       return pos;
-    if (pos->is_directory)
+    if (pos->is_directory == GNUNET_YES)
     {
       r = find_file_position (pos->data.dir.entries, srch);
       if (r != NULL)
index 0b8b088c49595d79f6f66d3ef447751477f2c652..4e5354e802c204167321f895d9f63aa1ba30bc00 100644 (file)
@@ -152,7 +152,7 @@ advance (struct GNUNET_FS_ShareTreeItem *pos)
   
   GNUNET_assert (NULL != pos);
   moved = 0; /* must not terminate, even on file, otherwise "normal" */
-  while ( (pos->is_directory) ||
+  while ( (pos->is_directory == GNUNET_YES) ||
          (0 == moved) )
   {
     if ( (moved != -1) &&
@@ -203,7 +203,7 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent,
   GNUNET_asprintf (&chld->short_filename,
                   "%s%s",
                   GNUNET_STRINGS_get_short_name (filename),
-                  is_directory ? "/" : "");
+                  is_directory == GNUNET_YES ? "/" : "");
   /* make sure we do not end with '//' */
   slen = strlen (chld->short_filename);
   if ( (slen >= 2) &&
@@ -325,7 +325,7 @@ process_helper_msgs (void *cls,
                           NULL, GNUNET_SYSERR,
                           GNUNET_FS_DIRSCANNER_ALL_COUNTED);
     ds->pos = ds->toplevel;
-    if (ds->pos->is_directory)
+    if (ds->pos->is_directory == GNUNET_YES)
       ds->pos = advance (ds->pos);
     return;
   case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA:
index a633dcb7b1264d550e54ca8e9535b85559af8bd3..85a076fee24f886ba9c508f0a37c2d3638ba7c7f 100644 (file)
@@ -324,7 +324,7 @@ int
 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
                                 struct GNUNET_FS_FileInformation *ent)
 {
-  if ((ent->dir != NULL) || (ent->next != NULL) || (!dir->is_directory))
+  if ((ent->dir != NULL) || (ent->next != NULL) || (dir->is_directory != GNUNET_YES))
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -362,12 +362,12 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
   no = GNUNET_NO;
   if (GNUNET_OK !=
       proc (proc_cls, dir,
-            (dir->is_directory) ? dir->data.dir.dir_size : dir->data.
+            (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size : dir->data.
             file.file_size, dir->meta, &dir->keywords, &dir->bo,
-            (dir->is_directory) ? &no : &dir->data.file.do_index,
+            (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index,
             &dir->client_info))
     return;
-  if (!dir->is_directory)
+  if (dir->is_directory != GNUNET_YES)
     return;
   pos = dir->data.dir.entries;
   while (pos != NULL)
@@ -375,9 +375,9 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
     no = GNUNET_NO;
     if (GNUNET_OK !=
         proc (proc_cls, pos,
-              (pos->is_directory) ? pos->data.dir.dir_size : pos->data.
+              (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size : pos->data.
               file.file_size, pos->meta, &pos->keywords, &pos->bo,
-              (pos->is_directory) ? &no : &pos->data.file.do_index,
+              (pos->is_directory == GNUNET_YES) ? &no : &pos->data.file.do_index,
               &pos->client_info))
       break;
     pos = pos->next;
@@ -404,7 +404,7 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
   int no;
 
   no = GNUNET_NO;
-  if (fi->is_directory)
+  if (fi->is_directory == GNUNET_YES)
   {
     /* clean up directory */
     while (NULL != (pos = fi->data.dir.entries))
index 315e3a157a355451e6294ac5b20e593575bb4bf8..1657e29e19c64c123c3cdf7c3d58a1735edc4202 100644 (file)
@@ -57,7 +57,7 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
   pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
   pi->value.publish.filename = p->filename;
   pi->value.publish.size =
-      (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
+      (p->is_directory == GNUNET_YES) ? p->data.dir.dir_size : p->data.file.file_size;
   pi->value.publish.eta =
       GNUNET_TIME_calculate_eta (p->start_time, offset, pi->value.publish.size);
   pi->value.publish.completed = offset;
@@ -132,7 +132,7 @@ ds_put_cont (void *cls, int success,
     pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
     pc->fi_pos->client_info =
         GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0);
-    if ((pc->fi_pos->is_directory == GNUNET_NO) &&
+    if ((pc->fi_pos->is_directory != GNUNET_YES) &&
         (pc->fi_pos->filename != NULL) &&
         (pc->fi_pos->data.file.do_index == GNUNET_YES))
     {
@@ -191,7 +191,7 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p,
   pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
   pi.value.publish.specifics.error.message = emsg;
   p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
-  if ((p->is_directory == GNUNET_NO) && (p->filename != NULL) &&
+  if ((p->is_directory != GNUNET_YES) && (p->filename != NULL) &&
       (p->data.file.do_index == GNUNET_YES))
   {
     /* run unindex to clean up */
@@ -347,7 +347,7 @@ block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
   const char *dd;
 
   p = pc->fi_pos;
-  if (p->is_directory)
+  if (p->is_directory == GNUNET_YES)
   {
     pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset);
     dd = p->data.dir.dir_data;
@@ -451,7 +451,7 @@ block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset,
     return;
   }
 
-  if ((!p->is_directory) && (GNUNET_YES == p->data.file.do_index) &&
+  if ((p->is_directory != GNUNET_YES) && (GNUNET_YES == p->data.file.do_index) &&
       (type == GNUNET_BLOCK_TYPE_FS_DBLOCK))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -462,7 +462,7 @@ block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset,
     odb.file_id = p->data.file.file_id;
     GNUNET_assert (pc->qre == NULL);
     pc->qre =
-        GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
+        GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid,
                               &chk->query, sizeof (struct OnDemandBlock), &odb,
                               GNUNET_BLOCK_TYPE_FS_ONDEMAND,
                               p->bo.content_priority, p->bo.anonymity_level,
@@ -477,7 +477,7 @@ block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset,
               (unsigned int) block_size);
   GNUNET_assert (pc->qre == NULL);
   pc->qre =
-      GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
+      GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid,
                             &chk->query, block_size, block, type,
                             p->bo.content_priority, p->bo.anonymity_level,
                             p->bo.replication_level, p->bo.expiration_time, -2,
@@ -535,14 +535,14 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
   GNUNET_assert (p != NULL);
   if (NULL == p->te)
   {
-    if (p->is_directory)
+    if (p->is_directory == GNUNET_YES)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n");
       db = GNUNET_FS_directory_builder_create (p->meta);
       dirpos = p->data.dir.entries;
       while (NULL != dirpos)
       {
-        if (dirpos->is_directory)
+        if (dirpos->is_directory == GNUNET_YES)
         {
           raw_data = dirpos->data.dir.dir_data;
           dirpos->data.dir.dir_data = NULL;
@@ -578,7 +578,7 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
                                           &p->data.dir.dir_data);
       GNUNET_FS_file_information_sync_ (p);
     }
-    size = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
+    size = (p->is_directory == GNUNET_YES) ? p->data.dir.dir_size : p->data.file.file_size;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n");
     p->te =
         GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader,
@@ -783,7 +783,7 @@ GNUNET_FS_publish_main_ (void *cls,
     return;
   }
   /* find starting position */
-  while ((p->is_directory) && (NULL != p->data.dir.entries) && (NULL == p->emsg)
+  while ((p->is_directory == GNUNET_YES) && (NULL != p->data.dir.entries) && (NULL == p->emsg)
          && (NULL == p->data.dir.entries->chk_uri))
   {
     p = p->data.dir.entries;
@@ -847,7 +847,7 @@ GNUNET_FS_publish_main_ (void *cls,
     }
     return;
   }
-  if ((!p->is_directory) && (p->data.file.do_index))
+  if ((p->is_directory != GNUNET_YES) && (p->data.file.do_index))
   {
     if (NULL == p->filename)
     {
index ca5f381757a68e1eabc32d4644c27b610515f6ad..c929428e1a58e9f4b4c7dfde49400cb3188e6cc4 100644 (file)
@@ -347,7 +347,7 @@ share_tree_trim (struct TrimContext *tc,
   }
 
   /* consider adding filename to directory meta data */
-  if (tree->is_directory)
+  if (tree->is_directory == GNUNET_YES)
   {
     const char *user = getenv ("USER");
     if ( (user == NULL) || 
index 94da0ce198f60c2826bf95a91132657c8eb80452..4f704640818e46a31fc741770a6dee576fd14267 100644 (file)
@@ -298,7 +298,7 @@ preprocess_file (const char *filename,
   item->filename = GNUNET_strdup (filename);
   item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO;
   item->file_size = (uint64_t) sbuf.st_size;
-  if (item->is_directory)
+  if (item->is_directory == GNUNET_YES)
   {
     struct RecursionContext rc;
 
@@ -334,7 +334,7 @@ extract_files (struct ScanTreeNode *item)
   ssize_t size;
   size_t slen;
 
-  if (item->is_directory)
+  if (item->is_directory == GNUNET_YES)
   {
     /* for directories, we simply only descent, no extraction, no
        progress reporting */
index 8f8d9147ca0a80bde2a7ac4ea67d803227874bdd..50f507d934bae26ffe1e0a087249aab0fa59bacd 100644 (file)
@@ -378,7 +378,7 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item)
   struct GNUNET_FS_FileInformation *fic;
   struct GNUNET_FS_ShareTreeItem *child;
 
-  if (item->is_directory)
+  if (item->is_directory == GNUNET_YES)
   {
     GNUNET_CONTAINER_meta_data_delete (item->meta,
         EXTRACTOR_METATYPE_MIMETYPE, NULL, 0);
@@ -481,7 +481,7 @@ directory_scan_cb (void *cls,
   case GNUNET_FS_DIRSCANNER_FILE_START:
     if (verbose > 1)
     {
-      if (is_directory)
+      if (is_directory == GNUNET_YES)
        FPRINTF (stdout, _("Scanning directory `%s'.\n"), filename);
       else
        FPRINTF (stdout, _("Scanning file `%s'.\n"), filename);