Repeatable: Always

Steps to Repeat:
1. Create content with a Video Field and upload a video
2. Edit the content, delete the video, upload another (e.g. revised) video with the exact same file name

Expected Results:
The original file is deleted from the filesystem as well as from the file_managed and file_usage tables.

Actual Results:
The file remains, and can cause issues later with identically named files. There is no way (that I could find) to clean this up via the UI and instead required direct editing of the filesystem and database.

Results after step1:

videos$ find . -type f
./original/Mean Kitty.mp4
./thumbnails/39/thumbnail-39_0001.jpg
./thumbnails/39/thumbnail-39_0002.jpg
./thumbnails/39/thumbnail-39_0003.jpg
./thumbnails/39/thumbnail-39_0004.jpg
./thumbnails/39/thumbnail-39_0005.jpg
psql=> select fid, filename, url, filemime, filesize, status from file_managed;
fid |       filename        |                         uri                         |  filemime  | filesize | status
-----+-----------------------+-----------------------------------------------------+------------+----------+--------
  39 | Mean Kitty.mp4        | public://videos/original/Mean Kitty.mp4             | video/mp4  | 10697161 |      1
  40 | thumbnail-39_0001.jpg | public://videos/thumbnails/39/thumbnail-39_0001.jpg | image/jpeg |     7777 |      1
  41 | thumbnail-39_0002.jpg | public://videos/thumbnails/39/thumbnail-39_0002.jpg | image/jpeg |     7454 |      1
  42 | thumbnail-39_0003.jpg | public://videos/thumbnails/39/thumbnail-39_0003.jpg | image/jpeg |     7477 |      1
  43 | thumbnail-39_0004.jpg | public://videos/thumbnails/39/thumbnail-39_0004.jpg | image/jpeg |     7357 |      1
  44 | thumbnail-39_0005.jpg | public://videos/thumbnails/39/thumbnail-39_0005.jpg | image/jpeg |     4944 |      1
(6 rows)
psql=> select * from file_usage;
fid | module | type | id | count
-----+--------+------+----+-------
  39 | file   | node | 33 |     1
  40 | file   | node | 33 |     1
  41 | file   | node | 33 |     1
  42 | file   | node | 33 |     1
  43 | file   | node | 33 |     1
  44 | file   | node | 33 |     1
(6 rows)

Results after step2:

videos$ find . -type f
./original/Mean Kitty.mp4
./original/Mean Kitty_0.mp4
./thumbnails/45/thumbnail-45_0001.jpg
./thumbnails/45/thumbnail-45_0002.jpg
./thumbnails/45/thumbnail-45_0003.jpg
./thumbnails/45/thumbnail-45_0004.jpg
./thumbnails/45/thumbnail-45_0005.jpg
psql=> select fid, filename, url, filemime, filesize, status from file_managed;
fid |       filename        |                         uri                         |  filemime  | filesize | status
-----+-----------------------+-----------------------------------------------------+------------+----------+--------
  39 | Mean Kitty.mp4        | public://videos/original/Mean Kitty.mp4             | video/mp4  | 10697161 |      1
  45 | Mean Kitty.mp4        | public://videos/original/Mean Kitty_0.mp4           | video/mp4  | 10697161 |      1
  46 | thumbnail-45_0001.jpg | public://videos/thumbnails/45/thumbnail-45_0001.jpg | image/jpeg |     7777 |      1
  47 | thumbnail-45_0002.jpg | public://videos/thumbnails/45/thumbnail-45_0002.jpg | image/jpeg |     7454 |      1
  48 | thumbnail-45_0003.jpg | public://videos/thumbnails/45/thumbnail-45_0003.jpg | image/jpeg |     7477 |      1
  49 | thumbnail-45_0004.jpg | public://videos/thumbnails/45/thumbnail-45_0004.jpg | image/jpeg |     7357 |      1
  50 | thumbnail-45_0005.jpg | public://videos/thumbnails/45/thumbnail-45_0005.jpg | image/jpeg |     4944 |      1
(7 rows)
drupal=> select * from file_usage;
fid | module | type | id | count
-----+--------+------+----+-------
  39 | file   | node | 33 |     1
  48 | file   | node | 33 |     1
  46 | file   | node | 33 |     1
  47 | file   | node | 33 |     1
  49 | file   | node | 33 |     1
  50 | file   | node | 33 |     1
  45 | file   | node | 33 |     1
(7 rows)

Results after deleting node:

videos$ find . -type f
./original/Mean Kitty.mp4
psql=> select fid, filename, url, filemime, filesize, status from file_managed;
fid |       filename        |                    uri                     |  filemime  | filesize | status
-----+-----------------------+--------------------------------------------+------------+----------+--------
  39 | Mean Kitty.mp4        | public://videos/original/Mean Kitty.mp4    | video/mp4  | 10697161 |      1
(1 row)
psql=> select * from file_usage;
fid | module | type | id | count
-----+--------+------+----+-------
  39 | file   | node | 33 |     1
(1 row)

Comments

Seems like this *could* be in some way related to #1468594: Delete old converted files after re-conversion.

Thanks for your thourough report. Could you try this again with the 7.x-2.x-dev version? I am not seeing the behavior that your are reporting.

The issue you are referring only relates to the usage of the reconvert checkbox, not with replacing the video. It should not influence replacing one video with another one.

Drupal should find out that a file with the same name exists and add a _0, _1, etc. When you replace a file with another file with the same name, you will always get a _0 because at the time you upload the second file, the first file still exists. When you save the node, the first file should be removed. According to your information, this doesn't happen, but for me it does.

clean-up is working for me, but I have noticed that video module leaves their containing folders (assuming you actually have some).

I store my videos in videos/original/[filename] - which gives a matching 'videos/converted/[fid]/[filename]' when files come back from zencoder.

Note(This folder functionality does not appear to be documented as far as I know) and if I don't specify an 'original' folder.. I dont get a 'converted' folder..... which I always found a bit odd....

Anyhows - on to the point. The 'converted/fid' folder doesn't get cleaned up which leaves me hundreds of empty folders on my system...