protected function setUp() { parent::setUp(); $this->tmpDir = \OC_Helper::tmpFolder() . 'dir.123' . DIRECTORY_SEPARATOR; mkdir($this->tmpDir); $this->instance = new \OC\Files\Storage\MappedLocal(array('datadir' => $this->tmpDir)); }
protected function setUp() { parent::setUp(); $this->user = new DummyUser('foo', \OC_Helper::tmpFolder()); $this->storage = new \OC\Files\Storage\Home(array('user' => $this->user)); $this->cache = $this->storage->getCache(); }
protected function setUp() { parent::setUp(); $this->datadir = \OC_Helper::tmpFolder(); file_put_contents($this->datadir . '/.ocdata', ''); \OC::$server->getSession()->set('checkServer_succeeded', false); }
public function setUp() { $this->tmpDir = \OC_Helper::tmpFolder(); $this->userId = uniqid('user_'); $this->user = new DummyUser($this->userId, $this->tmpDir); $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user)); }
protected function setUp() { parent::setUp(); $this->tmpDir = \OC_Helper::tmpFolder(); $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); $this->instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 10000000)); }
function setUp() { $this->randomTmpDir = \OC_Helper::tmpFolder(); $this->configFile = $this->randomTmpDir . 'testconfig.php'; file_put_contents($this->configFile, self::TESTCONTENT); $this->config = new OC\Config($this->randomTmpDir, 'testconfig.php'); }
protected function setUp() { parent::setUp(); $this->tmpDir = \OC_Helper::tmpFolder(); $this->userId = $this->getUniqueID('user_'); $this->user = new DummyUser($this->userId, $this->tmpDir); $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user)); }
protected function setUp() { parent::setUp(); \OC_Hook::clear('OC_Filesystem', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup'); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); $this->datadir = \OC_Config::getValue('datadirectory'); $this->tmpDir = \OC_Helper::tmpFolder(); \OC_Config::setValue('datadirectory', $this->tmpDir); $this->userBackend = new \OC_User_Dummy(); \OC_User::useBackend($this->userBackend); }
protected function setUp() { parent::setUp(); \OC_Hook::clear('OC_Filesystem', 'setup'); $application = new \OCA\Files_Sharing\AppInfo\Application(); $application->registerMountProviders(); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); $this->datadir = \OC_Config::getValue('datadirectory'); $this->tmpDir = \OC_Helper::tmpFolder(); \OC_Config::setValue('datadirectory', $this->tmpDir); $this->userBackend = new \Test\Util\User\Dummy(); \OC_User::useBackend($this->userBackend); }
/** * add an empty folder to the archive * * @param string $path * @return bool */ function addFolder($path) { $tmpBase = OC_Helper::tmpFolder(); if (substr($path, -1, 1) != '/') { $path .= '/'; } if ($this->fileExists($path)) { return false; } $parts = explode('/', $path); $folder = $tmpBase; foreach ($parts as $part) { $folder .= '/' . $part; if (!is_dir($folder)) { mkdir($folder); } } $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); rmdir($tmpBase . $path); $this->fileList = false; $this->cachedHeaders = false; return $result; }
public function xtestLongPath() { $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $rootView = new \OC\Files\View(''); $longPath = ''; $ds = DIRECTORY_SEPARATOR; /* * 4096 is the maximum path length in file_cache.path in *nix * 1024 is the max path length in mac * 228 is the max path length in windows */ $folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789'; $tmpdirLength = strlen(\OC_Helper::tmpFolder()); if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] '); $depth = (260 - $tmpdirLength) / 57; } elseif (\OC_Util::runningOnMac()) { $depth = (1024 - $tmpdirLength) / 57; } else { $depth = (4000 - $tmpdirLength) / 57; } foreach (range(0, $depth - 1) as $i) { $longPath .= $ds . $folderName; $result = $rootView->mkdir($longPath); $this->assertTrue($result, "mkdir failed on {$i} - path length: " . strlen($longPath)); $result = $rootView->file_put_contents($longPath . "{$ds}test.txt", 'lorem'); $this->assertEquals(5, $result, "file_put_contents failed on {$i}"); $this->assertTrue($rootView->file_exists($longPath)); $this->assertTrue($rootView->file_exists($longPath . "{$ds}test.txt")); } $cache = $storage->getCache(); $scanner = $storage->getScanner(); $scanner->scan(''); $longPath = $folderName; foreach (range(0, $depth - 1) as $i) { $cachedFolder = $cache->get($longPath); $this->assertTrue(is_array($cachedFolder), "No cache entry for folder at {$i}"); $this->assertEquals($folderName, $cachedFolder['name'], "Wrong cache entry for folder at {$i}"); $cachedFile = $cache->get($longPath . '/test.txt'); $this->assertTrue(is_array($cachedFile), "No cache entry for file at {$i}"); $this->assertEquals('test.txt', $cachedFile['name'], "Wrong cache entry for file at {$i}"); $longPath .= $ds . $folderName; } }
/** * @param array $data * @return array * @throws Exception */ public static function downloadApp($data = array()) { $l = \OC::$server->getL10N('lib'); if (!isset($data['source'])) { throw new \Exception($l->t("No source specified when installing app")); } //download the file if necessary if ($data['source'] == 'http') { $pathInfo = pathinfo($data['href']); $path = OC_Helper::tmpFile('.' . $pathInfo['extension']); if (!isset($data['href'])) { throw new \Exception($l->t("No href specified when installing app from http")); } copy($data['href'], $path); } else { if (!isset($data['path'])) { throw new \Exception($l->t("No path specified when installing app from local file")); } $path = $data['path']; } //detect the archive type $mime = OC_Helper::getMimeType($path); if ($mime !== 'application/zip' && $mime !== 'application/x-gzip') { throw new \Exception($l->t("Archives of type %s are not supported", array($mime))); } //extract the archive in a temporary folder $extractDir = OC_Helper::tmpFolder(); OC_Helper::rmdirr($extractDir); mkdir($extractDir); if ($archive = OC_Archive::open($path)) { $archive->extract($extractDir); } else { OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } throw new \Exception($l->t("Failed to open archive when installing app")); } return array($extractDir, $path); }
public function __construct($arguments = null) { parent::__construct(array('datadir' => \OC_Helper::tmpFolder())); }
public function setUp() { $this->tmpDir = \OC_Helper::tmpFolder(); $this->instance = new \OC\Files\Storage\CommonTest(array('datadir' => $this->tmpDir)); }
/** * @return array */ private function getStorageData() { $dir = OC_Helper::tmpFolder(); $this->tmpDirs[] = $dir; return array('datadir' => $dir); }
public function getLocalFolder($path) { $baseDir = \OC_Helper::tmpFolder(); $this->addLocalFolder($path, $baseDir); return $baseDir; }
/** * Tests recursive folder deletion with rmdirr() */ public function testRecursiveFolderDeletion() { $baseDir = \OC_Helper::tmpFolder() . '/'; mkdir($baseDir . 'a/b/c/d/e', 0777, true); mkdir($baseDir . 'a/b/c1/d/e', 0777, true); mkdir($baseDir . 'a/b/c2/d/e', 0777, true); mkdir($baseDir . 'a/b1/c1/d/e', 0777, true); mkdir($baseDir . 'a/b2/c1/d/e', 0777, true); mkdir($baseDir . 'a/b3/c1/d/e', 0777, true); mkdir($baseDir . 'a1/b', 0777, true); mkdir($baseDir . 'a1/c', 0777, true); file_put_contents($baseDir . 'a/test.txt', 'Hello file!'); file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!'); file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!'); \OC_Helper::rmdirr($baseDir . 'a'); $this->assertFalse(file_exists($baseDir . 'a')); $this->assertTrue(file_exists($baseDir . 'a1')); \OC_Helper::rmdirr($baseDir); $this->assertFalse(file_exists($baseDir)); }
public function setUp() { $this->tmpDir = \OC_Helper::tmpFolder(); $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); $this->instance = new \OC\Files\Storage\Wrapper\Wrapper(array('storage' => $storage)); }
protected function setUp() { parent::setUp(); $this->tmpDir = \OC_Helper::tmpFolder(); $this->instance = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); }
public function setUp() { $this->tmpDir = OC_Helper::tmpFolder(); $this->instance = new OC_Filestorage_Local(array('datadir' => $this->tmpDir)); }
/** * Test that an external cache is mounted into * the user's home */ public function testMountExternalCacheDir() { $userId = $this->getUniqueID('user_'); $oldCachePath = \OC_Config::getValue('cache_path', ''); // set cache path to temp dir $cachePath = \OC_Helper::tmpFolder() . '/extcache'; \OC_Config::setValue('cache_path', $cachePath); \OC_User::createUser($userId, $userId); \OC\Files\Filesystem::initMountPoints($userId); $this->assertEquals('/' . $userId . '/cache/', \OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')); list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache'); $this->assertTrue($storage->instanceOfStorage('\\OC\\Files\\Storage\\Local')); $this->assertEquals('', $internalPath); \OC_User::deleteUser($userId); \OC_Config::setValue('cache_path', $oldCachePath); }
/** * @brief Installs an app * @param $data array with all information * @throws \Exception * @returns integer * * This function installs an app. All information needed are passed in the * associative array $data. * The following keys are required: * - source: string, can be "path" or "http" * * One of the following keys is required: * - path: path to the file containing the app * - href: link to the downloadable file containing the app * * The following keys are optional: * - pretend: boolean, if set true the system won't do anything * - noinstall: boolean, if true appinfo/install.php won't be loaded * - inactive: boolean, if set true the appconfig/app.sample.php won't be * renamed * * This function works as follows * -# fetching the file * -# unzipping it * -# check the code * -# installing the database at appinfo/database.xml * -# including appinfo/install.php * -# setting the installed version * * It is the task of oc_app_install to create the tables and do whatever is * needed to get the app working. */ public static function installApp($data = array()) { $l = \OC_L10N::get('lib'); if (!isset($data['source'])) { throw new \Exception($l->t("No source specified when installing app")); } //download the file if necessary if ($data['source'] == 'http') { $pathInfo = pathinfo($data['href']); $path = OC_Helper::tmpFile('.' . $pathInfo['extension']); if (!isset($data['href'])) { throw new \Exception($l->t("No href specified when installing app from http")); } copy($data['href'], $path); } else { if (!isset($data['path'])) { throw new \Exception($l->t("No path specified when installing app from local file")); } $path = $data['path']; } //detect the archive type $mime = OC_Helper::getMimeType($path); if ($mime !== 'application/zip' && $mime !== 'application/x-gzip') { throw new \Exception($l->t("Archives of type %s are not supported", array($mime))); } //extract the archive in a temporary folder $extractDir = OC_Helper::tmpFolder(); OC_Helper::rmdirr($extractDir); mkdir($extractDir); if ($archive = OC_Archive::open($path)) { $archive->extract($extractDir); } else { OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } throw new \Exception($l->t("Failed to open archive when installing app")); } //load the info.xml file of the app if (!is_file($extractDir . '/appinfo/info.xml')) { //try to find it in a subdir $dh = opendir($extractDir); if (is_resource($dh)) { while (($folder = readdir($dh)) !== false) { if ($folder[0] != '.' and is_dir($extractDir . '/' . $folder)) { if (is_file($extractDir . '/' . $folder . '/appinfo/info.xml')) { $extractDir .= '/' . $folder; } } } } } if (!is_file($extractDir . '/appinfo/info.xml')) { OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } throw new \Exception($l->t("App does not provide an info.xml file")); } $info = OC_App::getAppInfo($extractDir . '/appinfo/info.xml', true); // check the code for not allowed calls if (!OC_Installer::checkCode($info['id'], $extractDir)) { OC_Helper::rmdirr($extractDir); throw new \Exception($l->t("App can't be installed because of not allowed code in the App")); } // check if the app is compatible with this version of ownCloud if (!isset($info['require']) or !OC_App::isAppVersionCompatible(OC_Util::getVersion(), $info['require'])) { OC_Helper::rmdirr($extractDir); throw new \Exception($l->t("App can't be installed because it is not compatible with this version of ownCloud")); } // check if shipped tag is set which is only allowed for apps that are shipped with ownCloud if (isset($info['shipped']) and $info['shipped'] == 'true') { OC_Helper::rmdirr($extractDir); throw new \Exception($l->t("App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps")); } // check if the ocs version is the same as the version in info.xml/version $versionFile = $extractDir . '/appinfo/version'; if (is_file($versionFile)) { $version = trim(file_get_contents($versionFile)); } else { $version = trim($info['version']); } if ($version != trim($data['appdata']['version'])) { OC_Helper::rmdirr($extractDir); throw new \Exception($l->t("App can't be installed because the version in info.xml/version is not the same as the version reported from the app store")); } $basedir = OC_App::getInstallPath() . '/' . $info['id']; //check if the destination directory already exists if (is_dir($basedir)) { OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } throw new \Exception($l->t("App directory already exists")); } if (isset($data['pretent']) and $data['pretent'] == true) { return false; } //copy the app to the correct place if (@(!mkdir($basedir))) { OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } throw new \Exception($l->t("Can't create app folder. Please fix permissions. %s", array($basedir))); } OC_Helper::copyr($extractDir, $basedir); //remove temporary files OC_Helper::rmdirr($extractDir); //install the database if (is_file($basedir . '/appinfo/database.xml')) { if (OC_Appconfig::getValue($info['id'], 'installed_version') === null) { OC_DB::createDbFromStructure($basedir . '/appinfo/database.xml'); } else { OC_DB::updateDbFromStructure($basedir . '/appinfo/database.xml'); } } //run appinfo/install.php if ((!isset($data['noinstall']) or $data['noinstall'] == false) and file_exists($basedir . '/appinfo/install.php')) { include $basedir . '/appinfo/install.php'; } //set the installed version OC_Appconfig::setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'])); OC_Appconfig::setValue($info['id'], 'enabled', 'no'); //set remote/public handelers foreach ($info['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, $info['id'] . '/' . $path); } foreach ($info['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, $info['id'] . '/' . $path); } OC_App::setAppTypes($info['id']); return $info['id']; }
public function __construct($arguments) { $this->datadir = OC_Helper::tmpFolder(); }
/** * create a temporary folder with an unique filename * @return string * * temporary files are automatically cleaned up after the script is finished */ public static function tmpFolder() { return \OC_Helper::tmpFolder(); }
/** * @brief Installs an app * @param $data array with all information * @returns integer * * This function installs an app. All information needed are passed in the * associative array $data. * The following keys are required: * - source: string, can be "path" or "http" * * One of the following keys is required: * - path: path to the file containing the app * - href: link to the downloadable file containing the app * * The following keys are optional: * - pretend: boolean, if set true the system won't do anything * - noinstall: boolean, if true appinfo/install.php won't be loaded * - inactive: boolean, if set true the appconfig/app.sample.php won't be * renamed * * This function works as follows * -# fetching the file * -# unzipping it * -# check the code * -# installing the database at appinfo/database.xml * -# including appinfo/install.php * -# setting the installed version * * It is the task of oc_app_install to create the tables and do whatever is * needed to get the app working. */ public static function installApp($data = array()) { if (!isset($data['source'])) { OC_Log::write('core', 'No source specified when installing app', OC_Log::ERROR); return false; } //download the file if necesary if ($data['source'] == 'http') { $path = OC_Helper::tmpFile(); if (!isset($data['href'])) { OC_Log::write('core', 'No href specified when installing app from http', OC_Log::ERROR); return false; } copy($data['href'], $path); } else { if (!isset($data['path'])) { OC_Log::write('core', 'No path specified when installing app from local file', OC_Log::ERROR); return false; } $path = $data['path']; } //detect the archive type $mime = OC_Helper::getMimeType($path); if ($mime == 'application/zip') { rename($path, $path . '.zip'); $path .= '.zip'; } elseif ($mime == 'application/x-gzip') { rename($path, $path . '.tgz'); $path .= '.tgz'; } else { OC_Log::write('core', 'Archives of type ' . $mime . ' are not supported', OC_Log::ERROR); return false; } //extract the archive in a temporary folder $extractDir = OC_Helper::tmpFolder(); OC_Helper::rmdirr($extractDir); mkdir($extractDir); if ($archive = OC_Archive::open($path)) { $archive->extract($extractDir); } else { OC_Log::write('core', 'Failed to open archive when installing app', OC_Log::ERROR); OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } return false; } //load the info.xml file of the app if (!is_file($extractDir . '/appinfo/info.xml')) { //try to find it in a subdir $dh = opendir($extractDir); while ($folder = readdir($dh)) { if (substr($folder, 0, 1) != '.' and is_dir($extractDir . '/' . $folder)) { if (is_file($extractDir . '/' . $folder . '/appinfo/info.xml')) { $extractDir .= '/' . $folder; } } } } if (!is_file($extractDir . '/appinfo/info.xml')) { OC_Log::write('core', 'App does not provide an info.xml file', OC_Log::ERROR); OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } return false; } $info = OC_App::getAppInfo($extractDir . '/appinfo/info.xml', true); $basedir = OC::$APPSROOT . '/apps/' . $info['id']; // check the code for not allowed calls if (!OC_Installer::checkCode($info['id'], $extractDir)) { OC_Log::write('core', 'App can\'t be installed because of not allowed code in the App', OC_Log::ERROR); OC_Helper::rmdirr($extractDir); return false; } // check if the app is compatible with this version of ownCloud $version = OC_Util::getVersion(); if (!isset($info['require']) or $version[0] > $info['require']) { OC_Log::write('core', 'App can\'t be installed because it is not compatible with this version of ownCloud', OC_Log::ERROR); OC_Helper::rmdirr($extractDir); return false; } //check if an app with the same id is already installed if (self::isInstalled($info['id'])) { OC_Log::write('core', 'App already installed', OC_Log::WARN); OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } return false; } //check if the destination directory already exists if (is_dir($basedir)) { OC_Log::write('core', 'App directory already exists', OC_Log::WARN); OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } return false; } if (isset($data['pretent']) and $data['pretent'] == true) { return false; } //copy the app to the correct place if (@(!mkdir($basedir))) { OC_Log::write('core', 'Can\'t create app folder. Please fix permissions. (' . $basedir . ')', OC_Log::ERROR); OC_Helper::rmdirr($extractDir); if ($data['source'] == 'http') { unlink($path); } return false; } OC_Helper::copyr($extractDir, $basedir); //remove temporary files OC_Helper::rmdirr($extractDir); //install the database if (is_file($basedir . '/appinfo/database.xml')) { OC_DB::createDbFromStructure($basedir . '/appinfo/database.xml'); } //run appinfo/install.php if ((!isset($data['noinstall']) or $data['noinstall'] == false) and file_exists($basedir . '/appinfo/install.php')) { include $basedir . '/appinfo/install.php'; } //set the installed version OC_Appconfig::setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'])); OC_Appconfig::setValue($info['id'], 'enabled', 'no'); //set remote/public handelers foreach ($info['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, '/apps/' . $info['id'] . '/' . $path); } foreach ($info['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, '/apps/' . $info['id'] . '/' . $path); } OC_App::setAppTypes($info['id']); return $info['id']; }