I'm working on a document management application on LAMP/php that lets you add and delete PDFs to our server. It works great, except for one nagging issue - the files you upload Monday might be gone Tuesday, and I can't diagnose why. it seems like the entire directory is getting deleted - my suspicion is that somewhere an incomplete string is getting passed to an unlink or something, but I've disabled every line of code I can find that removes files from the server and I'm still having trouble. How do I go about diagnosing the cause of these random disappearing files? Are there any utilities I can use to log any attempted removal of or changes to a file or directory?
8
-
1Change the permissions on the folders and see where errors start appearing.– ethrbunnyCommented Dec 30, 2012 at 21:14
-
here is a link that could help you: linuxos4all.blogspot.com/2010/11/…– pzirkindCommented Dec 30, 2012 at 21:18
-
@pzirkind: That won't work if the files are removed by a PHP script.– InternetSeriousBusinessCommented Dec 30, 2012 at 22:42
-
4Possible duplicate of serverfault.com/questions/304121/…– InternetSeriousBusinessCommented Dec 30, 2012 at 22:44
-
1It could be something outside your app, such as a cron running that prunes certain directories, though this is only likely if you're not alone on the server.– JormundirCommented Jan 6, 2013 at 0:42
|
Show 3 more comments
1 Answer
idealy you'd want to find your bug...
find codebase/ -type f -exec grep -il "unlink" '{}' \;
alertativley if you want a hacky fix, update your apache user to have a umask that would enable it to create files, but not delete them...
sed -i 's/^\(start|[a-z|-]*)\)/\1\n umask 0222/' `which apachectl`
also this would generate permission dennied errors in the error log...
-
find codebase/ -type f | xargs grep -sl "unlink "
is easier to remember ... just my 3.14 cents. Commented Jan 23, 2013 at 22:18 -
@Michael would you mind explaining what the find command does and how it will help solve the problem asked.– crafterCommented Aug 30, 2015 at 19:23