gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22069 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r22069 - gnunet/src/fs
Date: Mon, 18 Jun 2012 11:22:42 +0200

Author: grothoff
Date: 2012-06-18 11:22:42 +0200 (Mon, 18 Jun 2012)
New Revision: 22069

Modified:
   gnunet/src/fs/gnunet-auto-share.c
Log:
-implementing 'determine_id'

Modified: gnunet/src/fs/gnunet-auto-share.c
===================================================================
--- gnunet/src/fs/gnunet-auto-share.c   2012-06-18 09:07:38 UTC (rev 22068)
+++ gnunet/src/fs/gnunet-auto-share.c   2012-06-18 09:22:42 UTC (rev 22069)
@@ -224,15 +224,45 @@
  * Recursively scan the given file/directory structure to determine
  * a unique ID that represents the current state of the hierarchy.
  *
+ * @param cls where to store the unique ID we are computing
  * @param filename file to scan
- * @param id where to store the unique ID we computed
+ * @return GNUNET_OK (always)
  */
-static void
-determine_id (const char *filename,
-             struct GNUNET_HashCode *id)
+static int
+determine_id (void *cls,
+             const char *filename)
 {
-  // FIXME: implement!
-  GNUNET_break (0);
+  struct GNUNET_HashCode *id = cls;
+  struct stat sbuf;
+  struct GNUNET_HashCode fx[2];
+  struct GNUNET_HashCode ft;
+
+  if (0 != STAT (filename, &sbuf))
+  {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
+    return GNUNET_OK;
+  }
+  GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]);
+  if (!S_ISDIR (sbuf.st_mode))
+  {
+    uint64_t fsize = GNUNET_htonll (sbuf.st_size);
+
+    GNUNET_CRYPTO_hash (&fsize, sizeof (uint64_t), &fx[1]);
+  }
+  else
+  {
+    memset (&fx[1], 1, sizeof (struct GNUNET_HashCode));
+    GNUNET_DISK_directory_scan (filename,
+                               &determine_id,
+                               &fx[1]);
+  }
+  /* use hash here to make hierarchical structure distinct from
+     all files on the same level */
+  GNUNET_CRYPTO_hash (fx, sizeof (fx), &ft);
+  /* use XOR here so that order of the files in the directory 
+     does not matter! */
+  GNUNET_CRYPTO_hash_xor (&ft, id, id);
+  return GNUNET_OK;
 }
 
 
@@ -261,7 +291,7 @@
   wi = GNUNET_CONTAINER_multihashmap_get (work_finished,
                                          &key);
   memset (&id, 0, sizeof (struct GNUNET_HashCode));
-  determine_id (filename, &id);
+  determine_id (&id, filename);
   if (NULL != wi)
   {
     if (0 == memcmp (&id,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]