Exemplo n.º 1
0
 /**
  * tear down the filesystem, removing all storage providers
  */
 public static function tearDown()
 {
     self::clearMounts();
     self::$defaultInstance = null;
 }
Exemplo n.º 2
0
 /**
  * Fix common problems with a file path
  *
  * @param string $path
  * @param bool $stripTrailingSlash whether to strip the trailing slash
  * @param bool $isAbsolutePath whether the given path is absolute
  * @param bool $keepUnicode true to disable unicode normalization
  * @return string
  */
 public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false)
 {
     if (is_null(self::$normalizedPathCache)) {
         self::$normalizedPathCache = new CappedMemoryCache();
     }
     /**
      * FIXME: This is a workaround for existing classes and files which call
      *        this function with another type than a valid string. This
      *        conversion should get removed as soon as all existing
      *        function calls have been fixed.
      */
     $path = (string) $path;
     $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath]);
     if (isset(self::$normalizedPathCache[$cacheKey])) {
         return self::$normalizedPathCache[$cacheKey];
     }
     if ($path == '') {
         return '/';
     }
     //normalize unicode if possible
     if (!$keepUnicode) {
         $path = \OC_Util::normalizeUnicode($path);
     }
     //no windows style slashes
     $path = str_replace('\\', '/', $path);
     //add leading slash
     if ($path[0] !== '/') {
         $path = '/' . $path;
     }
     // remove '/./'
     // ugly, but str_replace() can't replace them all in one go
     // as the replacement itself is part of the search string
     // which will only be found during the next iteration
     while (strpos($path, '/./') !== false) {
         $path = str_replace('/./', '/', $path);
     }
     // remove sequences of slashes
     $path = preg_replace('#/{2,}#', '/', $path);
     //remove trailing slash
     if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') {
         $path = substr($path, 0, -1);
     }
     // remove trailing '/.'
     if (substr($path, -2) == '/.') {
         $path = substr($path, 0, -2);
     }
     $normalizedPath = $path;
     self::$normalizedPathCache[$cacheKey] = $normalizedPath;
     return $normalizedPath;
 }
Exemplo n.º 3
0
 /**
  * clear all mounts and storage backends
  */
 public static function clearMounts()
 {
     if (self::$mounts) {
         self::$usersSetup = array();
         self::$mounts->clear();
     }
 }