Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-49995

Orphaned files in moodle-data

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7.7
    • Fix Version/s: 3.3.4, 3.4.1
    • Component/s: Files API
    • Labels:
    • Testing Instructions:
      Hide
      1. For easier testing use completely empty site
      2. Run "ls -RF" in the moodledata/filedir , there should be 6 files (one of them is an empty file)
      3. Check mdl_files table, there are 5 files there and 2 directories (6 different hashes)
      4. Create a new course, turn editing mode on and drag and drop sample.pdf to it (as a resource)
      5. Check mdl_files table, new record with contenthash 'fc80d59877b4ae21911591b53664b2da1324cf25' appeared there
      6. Delete draft records from mdl_files ( DELETE FROM mdl_files WHERE filearea = 'draft'; ) - alternatively you could hack file_storage::cron() as in the issue description and run scheduled task file_trash_cleanup_task
      7. Run "ls -RF" in the moodledata/filedir , there should be 7 files now, new file for this hash was added
      8. Download sample2.pdf and rename it to sample.pdf on your HDD
      9. Edit the resource and drag and drop new sample.pdf over the existing one, choose to overwrite
      10. Check that the db table mdl_files no longer has contenthash of the first file (instead it has 'bfd009f500c057195ffde66fae64f92fa5f59b72')
      11. Run "ls -RF" in the moodledata/filedir , there should be 7 files now and the file for the original hash is not present
      12. Do not remove any draft files this time, edit the resource and drag and drop (with overwrite) the first file again
      13. Check mdl_files table and moodledata/filedir, both contenthashes should be present
      Show
      For easier testing use completely empty site Run "ls -RF" in the moodledata/filedir , there should be 6 files (one of them is an empty file) Check mdl_files table, there are 5 files there and 2 directories (6 different hashes) Create a new course, turn editing mode on and drag and drop sample.pdf to it (as a resource) Check mdl_files table, new record with contenthash 'fc80d59877b4ae21911591b53664b2da1324cf25' appeared there Delete draft records from mdl_files ( DELETE FROM mdl_files WHERE filearea = 'draft'; ) - alternatively you could hack file_storage::cron() as in the issue description and run scheduled task file_trash_cleanup_task Run "ls -RF" in the moodledata/filedir , there should be 7 files now, new file for this hash was added Download sample2.pdf and rename it to sample.pdf on your HDD Edit the resource and drag and drop new sample.pdf over the existing one, choose to overwrite Check that the db table mdl_files no longer has contenthash of the first file (instead it has 'bfd009f500c057195ffde66fae64f92fa5f59b72') Run "ls -RF" in the moodledata/filedir , there should be 7 files now and the file for the original hash is not present Do not remove any draft files this time, edit the resource and drag and drop (with overwrite) the first file again Check mdl_files table and moodledata/filedir, both contenthashes should be present
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_33_STABLE, MOODLE_34_STABLE
    • Pull Master Branch:
      wip-MDL-49995-master

      Description

      In some occasions it is possible, that users create orhaned files in moodledata. I found one of them:

      1. Create a file by mod_resource, make sure you have never used this file in this moodle instance
      2. Wait, until cron deletes user draft.
      3. After the deletion of the draft, overwrite the created file by e.g. drag-ad-drop

      Since it can take one week for the cron to delete the drafts, you may speed up this by the following steps:

      1. alter line 2168 from `lib/filestorage/file_storage.php` to `$time = time();` (Moodle 2.7)
      2. change value `nextruntime` of entry with classname `\core\task\file_trash_cleanup_task` in table ` {task_scheduled}

        ` to `lastruntime`

      3. execute /admin/cli/cron.php manually or wait for execution

      The code have to be rewinded afterwards, since they have huge impact on the system and usability. I recommend strongly to activate maintenance mode and backup your system!

      My Interpretation: Drag-and-drop overwrites the entries contenthash in DB, which leads to the point, that moodle doesn't know of the existence of the file anymore. We have now around 750 orphaned files in our moodle-data. A number, which will increase for sure. Please fix.

        Attachments

        1. sample2.pdf
          3 kB
        2. sample.pdf
          8 kB

          Activity

            People

            Assignee:
            marina Marina Glancy
            Reporter:
            eberhardt Jan Eberhardt
            Peer reviewer:
            Shamim Rezaie
            Integrator:
            Damyon Wiese
            Tester:
            Andrew Nicols
            Participants:
            Component watchers:
            Matteo Scaramuccia, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              15/Jan/18