When a file is deleted, it is still present in the index.
When searching something this file is indexed for, This error shows:

* warning: filectime() [function.filectime]: stat failed for C:/xampp/htdocs/drupal/sites/default/files/my_deleted_file.pdf in C:\xampp\htdocs\drupal\sites\all\modules\search_files\search_files.module on line 832.
* warning: filesize() [function.filesize]: stat failed for C:/xampp/htdocs/drupal/sites/default/files/my_deleted_file.pdf in C:\xampp\htdocs\drupal\sites\all\modules\search_files\search_files.module on line 834.

The deleted file is still listed in the search results with no number of bytes and no date.

Comments

leszek.hanusz’s picture

When the site is reindexed (by clicking on Reindex site and running cron jobs manually), the file does not appear in the results anymore and there is no errors anymore.

mradcliffe’s picture

Status: Active » Needs work

I ran into this bug as well, and can confirm it in search_files-6.x-1.6

There should be a test to confirm if the file exists or not. Here is what I did. This displays a watchdog notice if it doesn't exist.

--- search_files.module (revision 921)
+++ search_files.module (working copy)
@@ -807,24 +807,28 @@
         $search_results = db_query("SELECT * FROM {search_dataset} s WHERE sid = %d AND type = '%
s'", $item->sid, 'search_files');
         if ($dataset = db_fetch_object($search_results)) {
           //drupal_set_message('result = <pre>'.print_r($result, true).'</pre>');
-          $file_name = explode('/', $result->full_path);
-          $file_name = $file_name[count($file_name)-1];
-          $file_extension = explode('.', $file_name);
-          $file_extension = $file_extension[count($file_extension)-1];
-          $link = str_replace($doc_root, '', $result->full_path);
-          // we have had a problem where some links were returned relative to the search page,
-          // not the document root, basically there was no beginning forward slash '/' in the
-          // path
-          if (strpos($link, '/') !== 0) {
-            $link = '/'. $link;
-          }
-          $results[] = array(
-            'link' => $link,
-            'date' => filectime($result->full_path),
-            'type' => $file_extensions[$file_extension] .' file',
-            'title' => $file_name .' ('. format_size(filesize($result->full_path)) .')',
-            'snippet' => search_excerpt($keywords, $dataset->data),
-          );
+         if (! file_exists($result->full_path)) {
+           watchdog('search','Could not find file: %filename!',array('%filename' => $result->full
_path ), WATCHDOG_NOTICE, NULL);
+         } else {
+            $file_name = explode('/', $result->full_path);
+            $file_name = $file_name[count($file_name)-1];
+            $file_extension = explode('.', $file_name);
+            $file_extension = $file_extension[count($file_extension)-1];
+            $link = str_replace($doc_root, '', $result->full_path);
+            // we have had a problem where some links were returned relative to the search page,
+            // not the document root, basically there was no beginning forward slash '/' in the
+            // path
+            if (strpos($link, '/') !== 0) {
+              $link = '/'. $link;
+            }
+            $results[] = array(
+              'link' => $link,
+              'date' => filectime($result->full_path),
+              'type' => $file_extensions[$file_extension] .' file',
+              'title' => $file_name .' ('. format_size(filesize($result->full_path)) .')',
+              'snippet' => search_excerpt($keywords, $dataset->data),
+            );
+         }
         }
         date_default_timezone_set('MST');
       }
thl’s picture

See http://www.lotterer.net/blog/en/165-drupal-search_filesmodule-118thl1
The last one of these three bugfixes exactly handles the problem described in this thread.

bugfix
there is a functional gap where vanished files were not handled at all. Regularly compare database to filesystem and remove vanished files from database.

bugfix
while indexing files, skip over files which vanished before being indexed. Otherwise helper applications will get passed a nonexistent file name and fail.

bugfix
while preparing search results, skip over files which vanished after being indexed. Otherwise functions like filectime() will get passed a nonexistent file name and fail.

avpaderno’s picture

Title: Error when searching when a file is deleted - File still present in search ! » Error while searching a deleted file
thl’s picture

Assigned: Unassigned » jrglasgow

This is fixed on HEAD and will appear on >6.x-1.6, if someone releases any - James? I won't, so assign to jrglasgow. He should either roll a 6.x-1.7, find someone else who's doing it or set status to "won't fix". Sorry and best wishes.

avpaderno’s picture

Assigned: jrglasgow » Unassigned
Issue summary: View changes
Status: Needs work » Closed (outdated)

I am closing this issue, which is for a not supported Drupal version.