CC-2558 : Only delete files from disk that are in stor directory and not scheduled etc.

This commit is contained in:
Naomi Aro 2011-07-18 15:28:17 +02:00
parent 91feeaf84d
commit 4588ebd105
3 changed files with 27 additions and 20 deletions

View file

@ -133,10 +133,6 @@ class LibraryController extends Zend_Controller_Action
$this->view->message = "file doesn't exist";
return;
}
$data = array("filepath"=>$file->getFilePath());
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
$res = $file->delete();
@ -144,6 +140,10 @@ class LibraryController extends Zend_Controller_Action
$this->view->message = $res->getMessage();
return;
}
else {
$data = array("filepath" => $file->getFilePath(), "delete" => $res);
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
}
}
$this->view->id = $id;
@ -153,7 +153,7 @@ class LibraryController extends Zend_Controller_Action
{
$post = $this->getRequest()->getPost();
$datatables = StoredFile::searchFilesForPlaylistBuilder($post);
//format clip lengh to 1 decimal
foreach($datatables["aaData"] as &$data){
$sec = Playlist::playlistTimeToSeconds($data[5]);

View file

@ -326,7 +326,7 @@ class StoredFile {
* You cant delete a file if it is scheduled to be played in the future.
* The file will be removed from all playlists it is a part of.
*
* @return void|PEAR_Error
* @return boolean|PEAR_Error
*/
public function deleteFile()
{
@ -340,16 +340,18 @@ class StoredFile {
if (Schedule::IsFileScheduledInTheFuture($this->getId())) {
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
}
$storageDir = MusicDir::getStorDir()->getDirectory();
$dirCompare = substr($this->getFilePath(), 0, strlen($storageDir));
//return PEAR::raiseError("({$storageDir} , {$dirCompare})");
// Only delete the file from filesystem if it has been copied to the storage directory
if (substr($this->getFilePath(), 0, strlen($storageDir) == $storageDir)) {
// Delete the file
$res = unlink($this->getFilePath());
if (!$res) {
return PEAR::raiseError("StoredFile::deleteFile: unlink failed ({$this->getFilePath()})");
}
if ($dirCompare === $storageDir) {
return true;
}
else {
return false;
}
}
@ -373,7 +375,7 @@ class StoredFile {
*/
public function existsFile() {
$filepath = $this->_file->getDbFilepath();
$filepath = $this->getFilePath();
if (!isset($filepath) || !file_exists($filepath) || !is_readable($filepath)) {
return false;
@ -820,7 +822,7 @@ class StoredFile {
$stor = $storDir->getDirectory();
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
$r = @copy($audio_file, $audio_stor);
@ -838,8 +840,8 @@ class StoredFile {
// ." AND m.id = $dir_id";
$sql = "SELECT filepath as fp"
." FROM CC_FILES"
." WHERE directory = $dir_id";
." WHERE directory = $dir_id";
$rows = $CC_DBC->getAll($sql);
$results = array();

View file

@ -106,10 +106,15 @@ class AirtimeNotifier(Notifier):
self.watch_directory(new_storage_directory)
elif m['event_type'] == "file_delete":
self.logger.info("Deleting file: %s ", m['filepath'])
filepath = m['filepath'].encode('utf-8')
mm = self.proc_fun()
mm.add_filepath_to_ignore(m['filepath'])
os.unlink(m['filepath'])
self.logger.info("Adding file to ignore: %s ", filepath)
mm.add_filepath_to_ignore(filepath)
if m['delete'] == "true":
self.logger.info("Deleting file: %s ", filepath)
os.unlink(filepath)
#update airtime with information about files discovered in our