Пример #1
0
 /**
  * get the filesystem info from the cache
  * @param string path
  * @param string root (optional)
  * @return array
  *
  * returns an associative array with the following keys:
  * - size
  * - mtime
  * - ctime
  * - mimetype
  * - encrypted
  * - versioned
  */
 public static function get($path, $root = false)
 {
     if (OC_FileCache_Update::hasUpdated($path, $root)) {
         if ($root === false) {
             //filesystem hooks are only valid for the default root
             OC_Hook::emit('OC_Filesystem', 'post_write', array('path' => $path));
         } else {
             OC_FileCache_Update::update($path, $root);
         }
     }
     return OC_FileCache_Cached::get($path, $root);
 }
Пример #2
0
 public function copy($path1, $path2)
 {
     $postFix1 = substr($path1, -1, 1) === '/' ? '/' : '';
     $postFix2 = substr($path2, -1, 1) === '/' ? '/' : '';
     $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1));
     $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2));
     if (OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) {
         $path1 = $this->getRelativePath($absolutePath1);
         $path2 = $this->getRelativePath($absolutePath2);
         if ($path1 == null or $path2 == null) {
             return false;
         }
         $run = true;
         if ($this->fakeRoot == OC_Filesystem::getRoot()) {
             OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2, OC_Filesystem::signal_param_run => &$run));
             $exists = $this->file_exists($path2);
             if ($run and !$exists) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run));
             }
             if ($run) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run));
             }
         }
         if ($run) {
             $mp1 = $this->getMountPoint($path1 . $postFix1);
             $mp2 = $this->getMountPoint($path2 . $postFix2);
             if ($mp1 == $mp2) {
                 if ($storage = $this->getStorage($path1 . $postFix1)) {
                     $result = $storage->copy($this->getInternalPath($path1 . $postFix1), $this->getInternalPath($path2 . $postFix2));
                 }
             } else {
                 $source = $this->fopen($path1 . $postFix1, 'r');
                 $target = $this->fopen($path2 . $postFix2, 'w');
                 $result = OC_Helper::streamCopy($source, $target);
             }
             if ($this->fakeRoot == OC_Filesystem::getRoot()) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2));
                 if (!$exists) {
                     OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path2));
                 }
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path2));
             } else {
                 // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions
                 OC_FileCache_Update::update($path2, $this->fakeRoot);
                 OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot);
             }
             return $result;
         }
     }
 }
Пример #3
0
 public function copy($path1, $path2)
 {
     $postFix1 = substr($path1, -1, 1) === '/' ? '/' : '';
     $postFix2 = substr($path2, -1, 1) === '/' ? '/' : '';
     $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1));
     $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2));
     if (OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) {
         $path1 = $this->getRelativePath($absolutePath1);
         $path2 = $this->getRelativePath($absolutePath2);
         if ($path1 == null or $path2 == null) {
             return false;
         }
         $run = true;
         if ($this->fakeRoot == OC_Filesystem::getRoot()) {
             OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2, OC_Filesystem::signal_param_run => &$run));
             $exists = $this->file_exists($path2);
             if ($run and !$exists) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run));
             }
             if ($run) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run));
             }
         }
         if ($run) {
             $mp1 = $this->getMountPoint($path1 . $postFix1);
             $mp2 = $this->getMountPoint($path2 . $postFix2);
             if ($mp1 == $mp2) {
                 if ($storage = $this->getStorage($path1 . $postFix1)) {
                     $result = $storage->copy($this->getInternalPath($path1 . $postFix1), $this->getInternalPath($path2 . $postFix2));
                 }
             } else {
                 $source = $this->fopen($path1 . $postFix1, 'r');
                 $target = $this->fopen($path2 . $postFix2, 'w');
                 $result = OC_Helper::streamCopy($source, $target);
             }
             if ($this->fakeRoot == OC_Filesystem::getRoot()) {
                 // If the file to be copied originates within
                 // the user's data directory
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2));
                 if (!$exists) {
                     OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path2));
                 }
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path2));
             } else {
                 // If this is not a normal file copy operation
                 // and the file originates somewhere else
                 // (e.g. a version rollback operation), do not
                 // perform all the other post_write actions
                 // Update webdav properties
                 OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot);
                 $splitPath2 = explode('/', $path2);
                 // Only cache information about files
                 // that are being copied from within
                 // the user files directory. Caching
                 // other files, like VCS backup files,
                 // serves no purpose
                 if ($splitPath2[1] == 'files') {
                     OC_FileCache_Update::update($path2, $this->fakeRoot);
                 }
             }
             return $result;
         }
     }
 }