/** * @param string $fid * @return InputFile */ public function remove($fid) { $fileInfo = $this->get($fid); $involvedFiles = []; if ($fileInfo->reference) { // soft link should be deleted immediately $this->fileMetaModel->remove($fileInfo->id); $fileInfo->refCount--; $involvedFiles[] = $fileInfo; // decrease the source file reference count by 1 $involvedFiles[] = $this->fileMetaModel->decrFileRefCountById($fileInfo->reference); } else { // Source file is deleted and some other files refer to it // do nothing if ($fileInfo->deleted && $fileInfo->refCount > 0) { return; } // soft delete if ($fileInfo->refCount > 1) { $fileInfo = $this->fileMetaModel->softRemove($fileInfo); } else { $this->fileMetaModel->remove($fileInfo->id); // make sure the storage node would remove the file $fileInfo->refCount = 0; } $involvedFiles[] = $fileInfo; } if ($this->fileContainer) { foreach ($involvedFiles as $file) { $this->fileContainer->remove($file); } } }
/** * Remove file * @param $id string file id * @return bool|null */ public function remove($id) { // wait if the file is locked if (!$this->locker->lock($id)) { FileException::pop("The file \"{$id}\" is locked. Try later."); } $fileMeta = new FileMeta(); $fileContainer = new FileContainer(); $fileContainer->addHandler(new StorageNodeHandler()); $fileContainer->addHandler(new NodeMetaHandler()); $fileMeta->setFileContainer($fileContainer); $fileMeta->remove($id); $fileContainer->dump(); $this->locker->unlock($id); return true; }