Index: uuid.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.admin.inc,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 uuid.admin.inc
--- uuid.admin.inc	2 Apr 2010 02:17:52 -0000	1.1.2.6
+++ uuid.admin.inc	25 May 2010 11:57:23 -0000
@@ -63,6 +63,23 @@ function uuid_admin() {
     );
   }
 
+  if (module_exists('filefield')) {
+    $form['files'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Files settings'),
+    );
+    $form['files']['uuid_automatic_for_filefield'] = array(
+      '#type' => 'radios',
+      '#title' => t('Automatic UUID generation for filefield  files'),
+      '#default_value' => variable_get('uuid_automatic_for_filefield', FALSE),
+      '#options' => array(
+         TRUE => t('Enabled'),
+         FALSE => t('Disabled'),
+      ),
+      '#description' => t('Should UUIDs be created automatically for filefield uploaded files?'),
+    );
+  }
+
   $form['settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Synchronization'),
@@ -129,5 +146,11 @@ function uuid_sync() {
     }
   }
 
+  // Files
+  $result = db_query("SELECT fid, status FROM {files} WHERE status = 1 AND fid NOT IN (SELECT fid FROM {uuid_files})");
+  while ($item = db_fetch_object($result)) {
+    _uuid_file_insert_uuid($item);
+  }
+
   drupal_set_message(t("UUID tables have been updated."));
 }
Index: uuid.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.install,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 uuid.install
--- uuid.install	2 Apr 2010 02:20:38 -0000	1.1.2.8
+++ uuid.install	25 May 2010 11:57:23 -0000
@@ -32,6 +32,7 @@ function uuid_schema() {
     'uuid_users' => uuid_table_schema('users', 'uid'),
     'uuid_vocabulary' => uuid_table_schema('vocabulary', 'vid'),
     'uuid_term_data' => uuid_table_schema('term_data', 'tid'),
+    'uuid_files' => uuid_table_schema('files', 'fid'),
   );
 }
 
@@ -107,3 +108,14 @@ function uuid_update_6002() {
 
   return $ret;
 }
+
+/**
+ * Create uuid_files table.
+ */
+function uuid_update_6003() {
+  $ret = array();
+
+  db_create_table($ret, 'uuid_files', uuid_table_schema('files', 'fid'));
+
+  return $ret;
+}
Index: uuid.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.module,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 uuid.module
--- uuid.module	2 Apr 2010 02:17:52 -0000	1.1.2.10
+++ uuid.module	25 May 2010 11:57:24 -0000
@@ -200,6 +200,60 @@ function uuid_taxonomy($op, $type, $arra
 }
 
 /**
+ * Implementation of hook_file_insert().
+ *
+ * Support for filefields files.
+ */
+function uuid_file_insert(&$file) {
+  if (!variable_get('uuid_automatic_for_filefield', FALSE)) {
+    return;
+  }
+
+  _uuid_file_insert_uuid($file);
+}
+
+/**
+ * Implementation of hook_file_update().
+ *
+ * Support for filefields files.
+ */
+function uuid_file_update(&$file) {
+  if (!variable_get('uuid_automatic_for_filefield', FALSE)) {
+    return;
+  }
+
+  if (!db_result(db_query("SELECT fid FROM {uuid_files} WHERE fid = %d", $file->fid))) {
+    _uuid_file_insert_uuid($file);
+  }
+}
+
+/**
+ * Implementation of hook_file_delete().
+ *
+ * Support for filefields files.
+ */
+function uuid_file_delete($file) {
+  if (!variable_get('uuid_automatic_for_filefield', FALSE)) {
+    return;
+  }
+
+  db_query("DELETE FROM {uuid_files} WHERE fid = %d", $file->fid);
+}
+
+/**
+ * Insert the uid for a ile.
+ */
+function _uuid_file_insert_uuid(&$file) {
+  if ($file->fid && $file->status) {
+    $uuid = uuid_uuid();
+    db_query("INSERT INTO {uuid_files} (fid, uuid) VALUES (%d, '%s')",
+      $file->fid, $uuid);
+
+    $file->uuid = $uuid;
+  }
+}
+
+/**
  * Determines if a UUID is valid.
  */
 function uuid_is_valid($uuid) {
