Advertisement:

Author Topic: clean-out orphaned files from attachment folder  (Read 3360 times)

Offline RoyceMcKnight

  • Semi-Newbie
  • *
  • Posts: 32
  • I love gentoo
clean-out orphaned files from attachment folder
« on: July 14, 2008, 06:28:43 PM »
Heyho, I've searched the forums for half an hour, but could not find anything, so please forgive me if theres already a thread offering a solution to my problem.

My problem is: There are still files left in my attachment folder which already got deleted in my forum. I don't know how this has happend, particularly as it isn't happening anymore. Now when I delete an attachment from the forum, the file in the attchment folder gets deleted as well.

But I did some checking, and there are orphaned files in the attachment folder which have no corresponding entry in the database. So my question is: is there any way, maybe a little script, that could check my attachment folder for files which have no corresponding database entry and list them. Normally I would do this by hand, but with over 2.000 attachments this could take some time :-)
I use encrypted filenames.

I already used the attachment maintenance, but it does not incorporate checking for orphaned file leftovers.

Greetings from germany, Mike

kat

  • Guest
Re: clean-out orphaned files from attachment folder
« Reply #1 on: July 15, 2008, 04:37:12 PM »
It's not what you asked for, but wouldn't the "Remove attachments older than x days" do a close job to what you want?

Offline RoyceMcKnight

  • Semi-Newbie
  • *
  • Posts: 32
  • I love gentoo
Re: clean-out orphaned files from attachment folder
« Reply #2 on: July 15, 2008, 04:49:49 PM »
Hm no, this function would only remove active attachments from my forum, but not the orphaned files in the attachment folder. But I don't want any active attachment to be pruned out, they're all usefull :-)

kat

  • Guest
Re: clean-out orphaned files from attachment folder
« Reply #3 on: July 15, 2008, 04:55:43 PM »
Right. Yeah, I can see your problem.

Not a clue, myself. I'll keep an eye on this thread, though, to see if there IS a way.

Might help me out, too! :)

Offline greyknight17

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,890
  • Gender: Male
    • Kevin's Resource Center
Re: clean-out orphaned files from attachment folder
« Reply #4 on: July 19, 2008, 12:49:59 AM »
Go to Admin->Attachments and Avatars->File Maintenance and click on the Maintain link. See if that helps resolve the issue.

Offline RoyceMcKnight

  • Semi-Newbie
  • *
  • Posts: 32
  • I love gentoo
Re: clean-out orphaned files from attachment folder
« Reply #5 on: July 19, 2008, 03:32:07 AM »
Go to Admin->Attachments and Avatars->File Maintenance and click on the Maintain link. See if that helps resolve the issue.

I already used the attachment maintenance, but it does not incorporate checking for orphaned file leftovers.

I already tried that with no success :-)

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,806
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: clean-out orphaned files from attachment folder
« Reply #6 on: July 20, 2008, 04:05:34 AM »
Well that's a tough one, and I don't think it's possible. Due to the md5 hash assigned to a file name once it's saved and unique attachment ID.

Now you'll need to do a loop scan of the directory, removing the last 32 digits (md5 hash) and the first prefix attach ID number from the file (which can be variable so not sure how to get that one, maybe preg_replace from the ending _ of the ID?).  Ideally would like to use the function getAttachmentFilename() to get the clean file name, but without the original file name or attachment ID we can't use that function to remove the ID and/or md5 hash.

Then loop through the attachment table to compare and see if that filename is not longer referenced.  Now you run into issues with the fact you can use the same name more than once when file encryption is turned on.  So you can still get false positives.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

kat

  • Guest
Re: clean-out orphaned files from attachment folder
« Reply #7 on: July 20, 2008, 05:38:10 AM »
The only other manual way I can think of, is to delete them, using your ftp-client, looking at the datestamp on the file.

Bit long-winded, though, and not terribly accurate.

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,806
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: clean-out orphaned files from attachment folder
« Reply #8 on: July 20, 2008, 05:58:53 AM »
Datestamp will not indicate if it's still attached or an actual message or not though.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

kat

  • Guest
Re: clean-out orphaned files from attachment folder
« Reply #9 on: July 21, 2008, 03:10:41 PM »
No, of course not.

That's what I meant by "Not terribly accurate".

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,806
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: clean-out orphaned files from attachment folder
« Reply #10 on: July 23, 2008, 06:56:36 AM »
Yeah sorry to say currently no automated or easy way to do it.  It is strange that when the post was deleted it didn't remove the attachments in the first place.

I'd say [Mod] Request, but I can't see a way to do it with any certainty.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]