CC-2558 : Only delete files from disk that are in stor directory and not scheduled etc.
This commit is contained in:
parent
91feeaf84d
commit
4588ebd105
3 changed files with 27 additions and 20 deletions
|
@ -134,16 +134,16 @@ class LibraryController extends Zend_Controller_Action
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
$data = array("filepath"=>$file->getFilePath());
|
||||
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
|
||||
|
||||
$res = $file->delete();
|
||||
|
||||
if (PEAR::isError($res)) {
|
||||
$this->view->message = $res->getMessage();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$data = array("filepath" => $file->getFilePath(), "delete" => $res);
|
||||
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->id = $id;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
@ -342,14 +342,16 @@ class StoredFile {
|
|||
}
|
||||
|
||||
$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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue