Esempio n. 1
0
 /**
  * @brief When a file is deleted, remove its keyfile also
  */
 public function preUnlink($path)
 {
     // let the trashbin handle this
     if (\OCP\App::isEnabled('files_trashbin')) {
         return true;
     }
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $view = new \OC_FilesystemView('/');
     $userId = \OCP\USER::getUser();
     $util = new Util($view, $userId);
     // get relative path
     $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
     list($owner, $ownerPath) = $util->getUidAndFilename($relativePath);
     // Delete keyfile & shareKey so it isn't orphaned
     if (!Keymanager::deleteFileKey($view, $owner, $ownerPath)) {
         \OCP\Util::writeLog('Encryption library', 'Keyfile or shareKey could not be deleted for file "' . $ownerPath . '"', \OCP\Util::ERROR);
     }
     Keymanager::delAllShareKeys($view, $owner, $ownerPath);
     \OC_FileProxy::$enabled = $proxyStatus;
     // If we don't return true then file delete will fail; better
     // to leave orphaned keyfiles than to disallow file deletion
     return true;
 }