Esempio n. 1
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function Add()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) {
         try {
             $Target = Tools::CleanString(substr($_POST['FILE'], strrpos($_POST['FILE'], '/') + 1));
             // If target file exists, create a new one
             if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $Target)) {
                 $Target = time() . '_' . $Target;
             }
             // Create the target file if the downloader is Aria2
             if ($this->WhichDownloader == 0) {
                 \OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $Target);
             } else {
                 if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) {
                     \OC\Files\Filesystem::mkdir($this->DownloadsFolder);
                 }
             }
             // Build OPTIONS array
             $OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $Target, 'follow-torrent' => false);
             if (isset($_POST['OPTIONS']['FTPUser']) && strlen(trim($_POST['OPTIONS']['FTPUser'])) > 0 && isset($_POST['OPTIONS']['FTPPasswd']) && strlen(trim($_POST['OPTIONS']['FTPPasswd'])) > 0) {
                 $OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser'];
                 $OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd'];
             }
             if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) {
                 $OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false;
             }
             if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
                 $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
                 if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
                     $OPTIONS['all-proxy-user'] = $this->ProxyUser;
                     $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
                 }
             }
             $AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($_POST['FILE']), array('Params' => $OPTIONS)) : CURL::AddUri($_POST['FILE'], $OPTIONS);
             if (isset($AddURI['result']) && !is_null($AddURI['result'])) {
                 $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
                 if ($this->DbType == 1) {
                     $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
                 }
                 $Query = \OCP\DB::prepare($SQL);
                 $Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $Target, strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 1, time()));
                 sleep(1);
                 $Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($AddURI['result']) : CURL::TellStatus($AddURI['result']);
                 $Progress = 0;
                 if ($Status['result']['totalLength'] > 0) {
                     $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
                 }
                 $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);
                 return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 'ISTORRENT' => false));
             } else {
                 return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t($this->WhichDownloader == 0 ? 'Returned GID is null ! Is Aria2c running as a daemon ?' : 'An error occurred while running the CURL download')));
             }
         } catch (Exception $E) {
             return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
         }
     } else {
         return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided')));
     }
 }
 /**
  * @NoAdminRequired
  */
 public function savePersonal($savePath)
 {
     if (is_null($savePath)) {
         $savePath = '/';
     }
     $status = true;
     if (\OC\Files\Filesystem::file_exists($savePath) === false) {
         $status = \OC\Files\Filesystem::mkdir($savePath);
     }
     if ($status) {
         $this->appConfig->setUserValue($this->userId, 'save_path', $savePath);
         $response = array('status' => 'success', 'data' => array('message' => $this->l10n->t('Directory saved successfully.')));
     } else {
         $response = array('status' => 'error', 'data' => array('message' => $this->l10n->t('An error occurred while changing directory.')));
     }
     return $response;
 }
Esempio n. 3
0
 public function setUp()
 {
     parent::setUp();
     $this->userBackend = new \Test\Util\User\Dummy();
     \OC::$server->getUserManager()->registerBackend($this->userBackend);
     $this->ownerUid = $this->getUniqueID('owner_');
     $this->recipientUid = $this->getUniqueID('recipient_');
     $this->userBackend->createUser($this->ownerUid, '');
     $this->userBackend->createUser($this->recipientUid, '');
     $this->loginAsUser($this->ownerUid);
     Filesystem::mkdir('/foo');
     Filesystem::file_put_contents('/foo/bar.txt', 'asd');
     $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
     \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
     $this->loginAsUser($this->recipientUid);
     $this->assertTrue(Filesystem::file_exists('bar.txt'));
 }
Esempio n. 4
0
 public function __construct($AppName, IRequest $request, $UserId)
 {
     parent::__construct($AppName, $request);
     $this->userId = $UserId;
     $path = self::PROJECTKIT_PREFIX . DIRECTORY_SEPARATOR;
     if (isset($_GET['containerId'])) {
         $path .= self::PROJECT_PREFIX . (string) $_GET['containerId'] . DIRECTORY_SEPARATOR;
         if (isset($_GET['targetType']) && isset($_GET['targetId'])) {
             switch ($_GET['targetType']) {
                 case TargetType::TASK:
                     $path .= self::TASK_PREFIX;
                     break;
                 case TargetType::ISSUE:
                     $path .= self::ISSUE_PREFIX;
                     break;
                 default:
                     break;
             }
             $path .= (string) $_GET['targetId'] . DIRECTORY_SEPARATOR;
             $_SESSION['targetType'] = $_GET['targetType'];
         } elseif (!isset($_GET['targetType']) && !isset($_GET['targetId'])) {
             $_SESSION['targetType'] = TargetType::PROJECT;
         }
         //use session to save targetType
         $path = Filesystem::normalizePath($path);
         //Create folder for path
         if (!Filesystem::file_exists($path)) {
             try {
                 Filesystem::mkdir($path);
             } catch (\Exception $e) {
                 $result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
                 \OCP\JSON::error($result);
                 exit;
             }
         }
         if (!isset($_GET['dir'])) {
             $params = array_merge($_GET, ["dir" => $path]);
             $url = $_SERVER['PHP_SELF'] . '?' . http_build_query($params);
             header('Location: ' . $url, true, 302);
             exit;
         }
     }
 }
Esempio n. 5
0
 public function testNewUser()
 {
     $user1 = $this->getUniqueID('user_');
     $this->userBackend->createUser($user1, '');
     $this->loginAsUser($user1);
     Filesystem::mkdir('/folder');
     Filesystem::mkdir('/folder/subfolder');
     Filesystem::file_put_contents('/foo.txt', 'asd');
     Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
     Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
     $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
     $originalEtags = $this->getEtags($files);
     $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
     $scanner->backgroundScan('/');
     $newEtags = $this->getEtags($files);
     // loop over array and use assertSame over assertEquals to prevent false positives
     foreach ($originalEtags as $file => $originalEtag) {
         $this->assertSame($originalEtag, $newEtags[$file]);
     }
 }
Esempio n. 6
0
 /**
  * @medium
  */
 function testUnshareChildren()
 {
     $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
     $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // one folder should be shared with the user
     $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
     $this->assertCount(1, $shares);
     // move shared folder to 'localDir'
     \OC\Files\Filesystem::mkdir('localDir');
     $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
     $this->assertTrue($result);
     \OC\Files\Filesystem::unlink('localDir');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // after the parent directory was deleted the share should be unshared
     $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
     $this->assertEmpty($shares);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // the folder for the owner should still exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
 }
Esempio n. 7
0
 public function testNewUser()
 {
     $user1 = uniqid('user_');
     $this->userBackend->createUser($user1, '');
     \OC_Util::tearDownFS();
     \OC_User::setUserId($user1);
     \OC_Util::setupFS($user1);
     Filesystem::mkdir('/folder');
     Filesystem::mkdir('/folder/subfolder');
     Filesystem::file_put_contents('/foo.txt', 'asd');
     Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
     Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
     $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
     $originalEtags = $this->getEtags($files);
     $scanner = new \OC\Files\Utils\Scanner($user1);
     $scanner->backgroundScan('/');
     $newEtags = $this->getEtags($files);
     // loop over array and use assertSame over assertEquals to prevent false positives
     foreach ($originalEtags as $file => $originalEtag) {
         $this->assertSame($originalEtag, $newEtags[$file]);
     }
 }
Esempio n. 8
0
 /**
  * @medium
  */
 function testpreUnlink()
 {
     $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // one folder should be shared with the user
     $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
     $this->assertSame(1, count($sharedFolders));
     // move shared folder to 'localDir'
     \OC\Files\Filesystem::mkdir('localDir');
     $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
     $this->assertTrue($result);
     \OC\Files\Filesystem::unlink('localDir');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // after the parent directory was deleted the share should be unshared
     $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
     $this->assertTrue(empty($sharedFolders));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // the folder for the owner should still exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
 }
Esempio n. 9
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function Save()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     $Error = false;
     $Message = '';
     if (isset($_POST['KEY']) && strlen(trim($_POST['KEY'])) > 0 && isset($_POST['VAL']) && strlen(trim($_POST['VAL'])) > 0) {
         $PostKey = str_replace('OCD', '', $_POST['KEY']);
         $PostValue = ltrim(trim(str_replace(' ', '\\ ', $_POST['VAL'])), '/');
         if (in_array($PostKey, $this->OCDSettingKeys)) {
             $this->Settings->SetKey($PostKey);
             // Pre-Save process
             if (strcmp($PostKey, 'DownloadsFolder') == 0 || strcmp($PostKey, 'TorrentsFolder') == 0) {
                 // check folder exists, if not create it
                 if (!\OC\Files\Filesystem::is_dir($PostValue)) {
                     // Create the target file
                     \OC\Files\Filesystem::mkdir($PostValue);
                     $Message .= $this->L10N->t('The folder doesn\'t exist. It has been created.');
                 }
             }
             if (strlen(trim($PostValue)) <= 0) {
                 $PostValue = null;
             }
             if ($this->Settings->CheckIfKeyExists()) {
                 $this->Settings->UpdateValue($PostValue);
             } else {
                 $this->Settings->InsertValue($PostValue);
             }
         } else {
             $Error = true;
             $Message = $this->L10N->t('Unknown field');
         }
     } else {
         $Error = true;
         $Message = $this->L10N->t('Undefined field');
     }
     return new JSONResponse(array('ERROR' => $Error, 'MESSAGE' => strlen(trim($Message)) == 0 ? (string) $this->L10N->t('Saved') : $Message));
 }
Esempio n. 10
0
 public function viewToNodeProvider()
 {
     return [[function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'preWrite'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'postWrite'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'preCreate'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'postCreate'], [function () {
         Filesystem::mkdir('test.txt');
     }, 'preCreate'], [function () {
         Filesystem::mkdir('test.txt');
     }, 'postCreate'], [function () {
         Filesystem::touch('test.txt');
     }, 'preTouch'], [function () {
         Filesystem::touch('test.txt');
     }, 'postTouch'], [function () {
         Filesystem::touch('test.txt');
     }, 'preCreate'], [function () {
         Filesystem::touch('test.txt');
     }, 'postCreate'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
         Filesystem::unlink('test.txt');
     }, 'preDelete'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
         Filesystem::unlink('test.txt');
     }, 'postDelete'], [function () {
         Filesystem::mkdir('test.txt');
         Filesystem::rmdir('test.txt');
     }, 'preDelete'], [function () {
         Filesystem::mkdir('test.txt');
         Filesystem::rmdir('test.txt');
     }, 'postDelete']];
 }
Esempio n. 11
0
 /**
  * if a folder gets renamed all children mount points should be renamed too
  */
 function testRename()
 {
     $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // make sure that the shared folder exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
     \OC\Files\Filesystem::mkdir('oldTarget');
     \OC\Files\Filesystem::mkdir('oldTarget/subfolder');
     \OC\Files\Filesystem::mkdir('newTarget');
     \OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
     // re-login to make sure that the new mount points are initialized
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
     // re-login to make sure that the new mount points are initialized
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
     // cleanup
     $this->shareManager->deleteShare($share);
 }
Esempio n. 12
0
$l10n = \OC_L10n::get('files');
$result = array('success' => false, 'data' => NULL);
if (trim($foldername) === '') {
    $result['data'] = array('message' => $l10n->t('Folder name cannot be empty.'));
    OCP\JSON::error($result);
    exit;
}
if (strpos($foldername, '/') !== false) {
    $result['data'] = array('message' => $l10n->t('Folder name must not contain "/". Please choose a different name.'));
    OCP\JSON::error($result);
    exit;
}
//TODO why is stripslashes used on foldername here but not in newfile.php?
$target = $dir . '/' . stripslashes($foldername);
if (\OC\Files\Filesystem::file_exists($target)) {
    $result['data'] = array('message' => $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($foldername, $dir)));
    OCP\JSON::error($result);
    exit;
}
if (\OC\Files\Filesystem::mkdir($target)) {
    if ($dir !== '/') {
        $path = $dir . '/' . $foldername;
    } else {
        $path = '/' . $foldername;
    }
    $meta = \OC\Files\Filesystem::getFileInfo($path);
    $id = $meta['fileid'];
    OCP\JSON::success(array('data' => array('id' => $id)));
    exit;
}
OCP\JSON::error(array('data' => array('message' => $l10n->t('Error when creating the folder'))));
Esempio n. 13
0
 public function testDelete()
 {
     $textSize = strlen("dummy file data\n");
     $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
     $rootCachedData = $this->cache->get('');
     $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
     $this->assertTrue($this->cache->inCache('foo.txt'));
     Filesystem::unlink('foo.txt');
     $this->assertFalse($this->cache->inCache('foo.txt'));
     $cachedData = $this->cache->get('');
     $this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']);
     $this->assertInternalType('string', $rootCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
     $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
     $rootCachedData = $cachedData;
     Filesystem::mkdir('bar_folder');
     $this->assertTrue($this->cache->inCache('bar_folder'));
     $cachedData = $this->cache->get('');
     $this->assertInternalType('string', $rootCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
     $rootCachedData = $cachedData;
     Filesystem::rmdir('bar_folder');
     $this->assertFalse($this->cache->inCache('bar_folder'));
     $cachedData = $this->cache->get('');
     $this->assertInternalType('string', $rootCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
     $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
 }
Esempio n. 14
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function ListTorrentFiles()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     try {
         if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) {
             throw new \Exception((string) $this->L10N->t('You are not allowed to use the BitTorrent protocol'));
         }
         if (!\OC\Files\Filesystem::is_dir($this->TorrentsFolder)) {
             \OC\Files\Filesystem::mkdir($this->TorrentsFolder);
         }
         $this->TorrentsFolder = \OC\Files\Filesystem::normalizePath($this->TorrentsFolder);
         $Files = \OCA\Files\Helper::getFiles($this->TorrentsFolder, 'name', 'desc', 'application/octet-stream');
         $Files = \OCA\Files\Helper::formatFileInfos($Files);
         return new JSONResponse(array('ERROR' => false, 'FILES' => $Files));
     } catch (Exception $E) {
         return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
     }
 }
Esempio n. 15
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function Add()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) {
         try {
             if (!$this->AllowProtocolYT && !\OC_User::isAdminUser($this->CurrentUID)) {
                 throw new \Exception((string) $this->L10N->t('You are not allowed to use the YouTube protocol'));
             }
             $YouTube = new YouTube($this->YTDLBinary, $_POST['FILE']);
             if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
                 $YouTube->SetProxy($this->ProxyAddress, $this->ProxyPort);
             }
             if (isset($_POST['OPTIONS']['YTForceIPv4']) && strcmp($_POST['OPTIONS']['YTForceIPv4'], 'false') == 0) {
                 $YouTube->SetForceIPv4(false);
             }
             // Extract Audio YES
             if (isset($_POST['OPTIONS']['YTExtractAudio']) && strcmp($_POST['OPTIONS']['YTExtractAudio'], 'true') == 0) {
                 $VideoData = $YouTube->GetVideoData(true);
                 if (!isset($VideoData['AUDIO']) || !isset($VideoData['FULLNAME'])) {
                     return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube audio URL')));
                 }
                 $DL = array('URL' => $VideoData['AUDIO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Audio');
             } else {
                 $VideoData = $YouTube->GetVideoData();
                 if (!isset($VideoData['VIDEO']) || !isset($VideoData['FULLNAME'])) {
                     return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube video URL')));
                 }
                 $DL = array('URL' => $VideoData['VIDEO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Video');
             }
             // If target file exists, create a new one
             if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $DL['FILENAME'])) {
                 $DL['FILENAME'] = time() . '_' . $DL['FILENAME'];
             }
             // Create the target file if the downloader is ARIA2
             if ($this->WhichDownloader == 0) {
                 \OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $DL['FILENAME']);
             } else {
                 if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) {
                     \OC\Files\Filesystem::mkdir($this->DownloadsFolder);
                 }
             }
             $OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $DL['FILENAME']);
             if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
                 $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
                 if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
                     $OPTIONS['all-proxy-user'] = $this->ProxyUser;
                     $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
                 }
             }
             if (!is_null($this->MaxDownloadSpeed) && $this->MaxDownloadSpeed > 0) {
                 $OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K';
             }
             $AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($DL['URL']), array('Params' => $OPTIONS)) : CURL::AddUri($DL['URL'], $OPTIONS);
             if (isset($AddURI['result']) && !is_null($AddURI['result'])) {
                 $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
                 if ($this->DbType == 1) {
                     $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
                 }
                 $Query = \OCP\DB::prepare($SQL);
                 $Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $DL['FILENAME'], $DL['TYPE'], 1, time()));
                 sleep(1);
                 $Status = Aria2::TellStatus($AddURI['result']);
                 $Progress = 0;
                 if ($Status['result']['totalLength'] > 0) {
                     $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
                 }
                 $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);
                 return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($DL['FILENAME']) > 40 ? substr($DL['FILENAME'], 0, 40) . '...' : $DL['FILENAME'], 'PROTO' => $DL['TYPE'], 'ISTORRENT' => false));
             } else {
                 return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Returned GID is null ! Is Aria2c running as a daemon ?')));
             }
         } catch (Exception $E) {
             return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
         }
     } else {
         return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided')));
     }
 }
Esempio n. 16
0
 function testRenameInSharedFolder()
 {
     \OC\Files\Filesystem::mkdir('folder1');
     \OC\Files\Filesystem::mkdir('folder1/folder2');
     \OC\Files\Filesystem::file_put_contents("folder1/test.txt", "test file");
     $fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
     $t1 = time();
     // second version is two weeks older, this way we make sure that no
     // version will be expired
     $t2 = $t1 - 60 * 60 * 24 * 14;
     $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1');
     // create some versions
     $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1;
     $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2;
     $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t1;
     $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t2;
     $this->rootView->file_put_contents($v1, 'version1');
     $this->rootView->file_put_contents($v2, 'version2');
     \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, OCP\PERMISSION_ALL);
     self::loginHelper(self::TEST_VERSIONS_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('folder1/test.txt'));
     // execute rename hook of versions app
     \OC\Files\Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt');
     self::loginHelper(self::TEST_VERSIONS_USER2);
     $this->assertFalse($this->rootView->file_exists($v1));
     $this->assertFalse($this->rootView->file_exists($v2));
     $this->assertTrue($this->rootView->file_exists($v1Renamed));
     $this->assertTrue($this->rootView->file_exists($v2Renamed));
     //cleanup
     \OC\Files\Filesystem::unlink('/folder1/folder2/test.txt');
 }
Esempio n. 17
0
         if ($mtime == 0) {
             $msg = "File already exists!";
         } else {
             $msg = "File has been modified since opening!";
         }
         OCP\JSON::error(array("data" => array("message" => $msg)));
         //OCP\Util::writeLog('files_svgedit',"File: ".$path." modified since opening.",OC_Log::ERROR);
         exit;
     }
 } else {
     // file doesn't exist yet, so let's create it!
     if ($file == '') {
         OCP\JSON::error(array("data" => array("message" => "Empty Filename")));
         exit;
     }
     \OC\Files\Filesystem::mkdir($dir);
     if (!\OC\Files\Filesystem::touch($dir . '/' . $file)) {
         OCP\JSON::error(array("data" => array("message" => "Error when creating new file!")));
         OCP\Util::writeLog('files_svgedit', "Failed to create file: " . $path, OC_Log::ERROR);
         exit;
     }
 }
 // file should be existing now
 $writable = \OC\Files\Filesystem::isUpdatable($path);
 if ($writable) {
     if ($b64encoded) {
         $b64prefix = 'data:' . $b64type . ';base64,';
         if (strpos($filecontents, $b64prefix) === 0) {
             $filecontents = base64_decode(substr($filecontents, strlen($b64prefix)));
         }
     }
Esempio n. 18
0
 /**
  * @dataProvider usersProvider
  */
 function testMoveFileToFolder($userId)
 {
     $view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1);
     $filename = '/tmp-' . $this->getUniqueID();
     $folder = '/folder' . $this->getUniqueID();
     \OC\Files\Filesystem::mkdir($folder);
     // Save long data as encrypted file using stream wrapper
     $cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort);
     // Test that data was successfully written
     $this->assertInternalType('int', $cryptedFile);
     // Get file decrypted contents
     $decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename);
     $this->assertEquals($this->dataShort, $decrypt);
     $subFolder = $folder . '/subfolder' . $this->getUniqueID();
     \OC\Files\Filesystem::mkdir($subFolder);
     // get the file info from previous created file
     $fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
     // share the folder
     \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);
     // check that the share keys exist
     $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
     $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // move the file into the subfolder as the test user
     self::loginHelper($userId);
     \OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
     // Get file decrypted contents
     $newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename);
     $this->assertEquals($this->dataShort, $newDecrypt);
     // check if additional share key for user2 exists
     $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
     $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // check that old keys were removed/moved properly
     $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
     $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // tear down
     \OC\Files\Filesystem::unlink($subFolder);
     \OC\Files\Filesystem::unlink($folder);
 }
Esempio n. 19
0
 public function testHooks()
 {
     if (\OC\Files\Filesystem::getView()) {
         $user = \OC_User::getUser();
     } else {
         $user = $this->getUniqueID();
         \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     }
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $rootView = new \OC\Files\View('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     //		\OC\Files\Filesystem::file_put_contents('/foo', 'foo');
     \OC\Files\Filesystem::mkdir('/bar');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = \OC_Helper::tmpFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
 }
Esempio n. 20
0
<?php

// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get the params
$dir = isset($_POST['dir']) ? stripslashes($_POST['dir']) : '';
$foldername = isset($_POST['foldername']) ? stripslashes($_POST['foldername']) : '';
if (trim($foldername) == '') {
    OCP\JSON::error(array("data" => array("message" => "Empty Foldername")));
    exit;
}
if (strpos($foldername, '/') !== false) {
    OCP\JSON::error(array("data" => array("message" => "Invalid Foldername")));
    exit;
}
if (\OC\Files\Filesystem::mkdir($dir . '/' . stripslashes($foldername))) {
    if ($dir != '/') {
        $path = $dir . '/' . $foldername;
    } else {
        $path = '/' . $foldername;
    }
    $meta = \OC\Files\Filesystem::getFileInfo($path);
    $id = $meta['fileid'];
    OCP\JSON::success(array("data" => array('id' => $id)));
    exit;
}
OCP\JSON::error(array("data" => array("message" => "Error when creating the folder")));
Esempio n. 21
0
 /**
  * test expiration of files older then the max storage time defined for the trash
  * in this test we delete a shared file and check if both trash bins, the one from
  * the owner of the file and the one from the user who deleted the file get expired
  * correctly
  */
 public function testExpireOldFilesShared()
 {
     $currentTime = time();
     $folder = "trashTest-" . $currentTime . '/';
     $expiredDate = $currentTime - 3 * 24 * 60 * 60;
     // create some files
     \OC\Files\Filesystem::mkdir($folder);
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-1.txt', 'file1');
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-2.txt', 'file2');
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-3.txt', 'file3');
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
     //share user1-4.txt with user2
     $fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
     $result = \OCP\Share::shareItem('folder', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_TRASHBIN_USER2, 31);
     $this->assertTrue($result);
     // delete them so that they end up in the trash bin
     \OC\Files\Filesystem::unlink($folder . 'user1-1.txt');
     \OC\Files\Filesystem::unlink($folder . 'user1-2.txt');
     \OC\Files\Filesystem::unlink($folder . 'user1-3.txt');
     $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
     $this->assertSame(3, count($filesInTrash));
     // every second file will get a date in the past so that it will get expired
     $this->manipulateDeleteTime($filesInTrash, $this->trashRoot1, $expiredDate);
     // login as user2
     self::loginHelper(self::TEST_TRASHBIN_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($folder . "user1-4.txt"));
     // create some files
     \OC\Files\Filesystem::file_put_contents('user2-1.txt', 'file1');
     \OC\Files\Filesystem::file_put_contents('user2-2.txt', 'file2');
     // delete them so that they end up in the trash bin
     \OC\Files\Filesystem::unlink('user2-1.txt');
     \OC\Files\Filesystem::unlink('user2-2.txt');
     $filesInTrashUser2 = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2, 'name');
     $this->assertSame(2, count($filesInTrashUser2));
     // every second file will get a date in the past so that it will get expired
     $this->manipulateDeleteTime($filesInTrashUser2, $this->trashRoot2, $expiredDate);
     \OC\Files\Filesystem::unlink($folder . 'user1-4.txt');
     $this->runCommands();
     $filesInTrashUser2AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2);
     // user2-1.txt should have been expired
     $this->verifyArray($filesInTrashUser2AfterDelete, array('user2-2.txt', 'user1-4.txt'));
     self::loginHelper(self::TEST_TRASHBIN_USER1);
     // user1-1.txt and user1-3.txt should have been expired
     $filesInTrashUser1AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
     $this->verifyArray($filesInTrashUser1AfterDelete, array('user1-2.txt', 'user1-4.txt'));
 }
Esempio n. 22
0
 /**
  * Creates a new subdirectory
  *
  * @param string $name
  * @throws Sabre_DAV_Exception_Forbidden
  * @return void
  */
 public function createDirectory($name)
 {
     if ($name === 'Shared' && empty($this->path)) {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     if (!\OC\Files\Filesystem::isCreatable($this->path)) {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     $newPath = $this->path . '/' . $name;
     if (!\OC\Files\Filesystem::mkdir($newPath)) {
         throw new Sabre_DAV_Exception_Forbidden('Could not create directory ' . $newPath);
     }
 }
Esempio n. 23
0
 public function testGetPathByIdShareSubFolder()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OC\Files\Filesystem::mkdir('foo');
     \OC\Files\Filesystem::mkdir('foo/bar');
     \OC\Files\Filesystem::touch('foo/bar/test.txt');
     $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
     $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
     $node = $rootFolder->get('foo');
     $share = $this->shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $this->shareManager->createShare($share);
     \OC_Util::tearDownFS();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
     list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
     /**
      * @var \OC\Files\Storage\Shared $sharedStorage
      */
     $sharedCache = $sharedStorage->getCache();
     $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
     $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
 }
Esempio n. 24
0
 /**
  * Test whether versions are created when overwriting as share recipient
  */
 public function testStoreVersionAsRecipient()
 {
     $this->loginAsUser(self::TEST_VERSIONS_USER);
     \OC\Files\Filesystem::mkdir('folder');
     \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
     $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder');
     $share = \OC::$server->getShareManager()->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedBy(self::TEST_VERSIONS_USER)->setSharedWith(self::TEST_VERSIONS_USER2)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $share = \OC::$server->getShareManager()->createShare($share);
     $this->loginAsUser(self::TEST_VERSIONS_USER2);
     $this->createAndCheckVersions(\OC\Files\Filesystem::getView(), 'folder/test.txt');
     \OC::$server->getShareManager()->deleteShare($share);
 }
Esempio n. 25
0
 /**
  * Test whether versions are created when overwriting as share recipient
  */
 public function testStoreVersionAsRecipient()
 {
     $this->loginAsUser(self::TEST_VERSIONS_USER);
     \OC\Files\Filesystem::mkdir('folder');
     \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
     \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
     $this->loginAsUser(self::TEST_VERSIONS_USER2);
     $this->createAndCheckVersions(\OC\Files\Filesystem::getView(), 'folder/test.txt');
 }
Esempio n. 26
0
 /**
  * if a folder gets renamed all children mount points should be renamed too
  */
 function testRename()
 {
     $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // make sure that the shared folder exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
     \OC\Files\Filesystem::mkdir('oldTarget');
     \OC\Files\Filesystem::mkdir('oldTarget/subfolder');
     \OC\Files\Filesystem::mkdir('newTarget');
     \OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
     // re-login to make sure that the new mount points are initialized
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
     // re-login to make sure that the new mount points are initialized
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
     // cleanup
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
 }
Esempio n. 27
0
 public function testGetPathByIdShareSubFolder()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OC\Files\Filesystem::mkdir('foo');
     \OC\Files\Filesystem::mkdir('foo/bar');
     \OC\Files\Filesystem::touch('foo/bar/test.txt', 'bar');
     $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\PERMISSION_ALL);
     \OC_Util::tearDownFS();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
     list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
     /**
      * @var \OC\Files\Storage\Shared $sharedStorage
      */
     $sharedCache = $sharedStorage->getCache();
     $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
     $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
 }
Esempio n. 28
0
 /**
  * Copies a file or directory.
  *
  * This method must work recursively and delete the destination
  * if it exists
  *
  * @param string $source
  * @param string $destination
  * @return void
  */
 public function copy($source, $destination)
 {
     if (Filesystem::is_file($source)) {
         Filesystem::copy($source, $destination);
     } else {
         Filesystem::mkdir($destination);
         $dh = Filesystem::opendir($source);
         if (is_resource($dh)) {
             while (($subnode = readdir($dh)) !== false) {
                 if ($subnode == '.' || $subnode == '..') {
                     continue;
                 }
                 $this->copy($source . '/' . $subnode, $destination . '/' . $subnode);
             }
         }
     }
     list($destinationDir, ) = \Sabre_DAV_URLUtil::splitPath($destination);
     $this->markDirty($destinationDir);
 }
Esempio n. 29
0
 /**
  * get default share folder
  *
  * @return string
  */
 public static function getShareFolder()
 {
     $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
     $shareFolder = Filesystem::normalizePath($shareFolder);
     if (!Filesystem::file_exists($shareFolder)) {
         $dir = '';
         $subdirs = explode('/', $shareFolder);
         foreach ($subdirs as $subdir) {
             $dir = $dir . '/' . $subdir;
             if (!Filesystem::is_dir($dir)) {
                 Filesystem::mkdir($dir);
             }
         }
     }
     return $shareFolder;
 }
Esempio n. 30
0
 public function testHooks()
 {
     if (\OC\Files\Filesystem::getView()) {
         $user = \OC_User::getUser();
     } else {
         $user = self::TEST_FILESYSTEM_USER1;
         $backend = new \Test\Util\User\Dummy();
         \OC_User::useBackend($backend);
         $backend->createUser($user, $user);
         $userObj = \OC::$server->getUserManager()->get($user);
         \OC::$server->getUserSession()->setUser($userObj);
         \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     }
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $rootView = new \OC\Files\View('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     //		\OC\Files\Filesystem::file_put_contents('/foo', 'foo');
     \OC\Files\Filesystem::mkdir('/bar');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
 }