Index: flashvideo.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flashvideo/flashvideo.module,v
retrieving revision 1.73.2.112
diff -u -r1.73.2.112 flashvideo.module
--- flashvideo.module 16 Aug 2009 22:08:30 -0000  1.73.2.112
+++ flashvideo.module 23 Aug 2009 06:50:50 -0000
@@ -1019,6 +1019,8 @@
       if (module_exists('token')) {
         $filefield_path = token_replace($filefield_path, 'user', $account);
       }
+      $output_directory = file_directory_path() .'/'. $filefield_path;
+      file_check_directory($output_directory,TRUE);
       $newfile->filepath = file_directory_path() .'/'. $filefield_path .'/'. $newfile->filename;
     }
 
@@ -1577,6 +1579,27 @@
         $file = (object)$file;
         // Only continue if it is a video
         if (_flashvideo_get_mime_type($file->filepath) !== FALSE) {
+          /*
+           * If they want to remove a file and upload a new one
+           */
+          if(isset($node->$cck_finished_video_field['field_name']) && sizeof($node->$cck_finished_video_field['field_name']) == 1){
+            $file_finished = $node->$cck_finished_video_field['field_name'];
+            $file_finished = (object)$file_finished[0];
+          }
+          if(isset($node->$cck_finished_thumbnail_field['field_name']) && sizeof($node->$cck_finished_thumbnail_field['field_name']) == 1){
+            $file_thumb = $node->$cck_finished_thumbnail_field['field_name'];
+            $file_thumb = (object)$file_thumb[0];
+          }
+          //Look if the file in filefield is a new one
+          if($file->fid > $file_finished->fid && $file->fid > $file_thumb->fid){
+            
+            file_delete_by_id($file_finished->fid);
+            file_delete_by_id($file_thumb->fid);
+            $result = db_fetch_object(db_query('SELECT oid FROM {flashvideo} WHERE fid = %d',$file_finished->fid));
+            //unpublish the node
+            db_query('UPDATE {node} SET status = 0 WHERE nid = %d',$node->nid);
+            db_query('DELETE FROM {flashvideo} WHERE oid = %d',$result->oid);
+          }
           // Is this file already part of the flashvideo table?
           $found = db_result(db_query("SELECT count(*) FROM {flashvideo} WHERE fid=%d", $file->fid));
           // Only add if the file is a video and is not already in our flashvideo table.
