public function testChmod() { if (AdvancedPathLib::getCurrentOS() == AdvancedPathLib::OS_WINDOWS) { $this->markTestSkipped('chmod() is not available on Windows.'); } $this->assertNotEquals('-rwxr-xr--', AdvancedPathLib::permsToUnix(fileperms(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'))); $this->assertTrue($this->fixture_file->chmod(0754)); clearstatcache(); $this->assertEquals('-rwxr-xr--', AdvancedPathLib::permsToUnix(fileperms(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'))); }
/** * @param int $mode The mode. Default is 0777 - umask. * @return bool TRUE if the directory has been successfully created, FALSE otherwise. * @throws EyeIOException * @throws EyeInvalidArgumentException */ public function mkdir($mode = null) { if ($this->realFile === null) { throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path); } if ($mode === null) { $mode = 0777 & ~$this->getUMask(); } if (!is_int($mode)) { throw new EyeInvalidArgumentException($mode . ' is not a valid octal value for $mode.'); } $this->getParentFile()->checkWritePermission(); if ($this->realFile->mkdir()) { MetaManager::getInstance()->deleteMeta($this); $meta = MetaManager::getInstance()->getNewMetaDataInstance($this); if ($meta !== null) { $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $group = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosGroup(); $meta->set(self::METADATA_KEY_OWNER, $currentUser->getName()); $meta->set(self::METADATA_KEY_GROUP, $group->getName()); $meta->set(self::METADATA_KEY_CREATIONTIME, time()); $meta->set(self::METADATA_KEY_MODIFICATIONTIME, time()); $meta->set(self::METADATA_KEY_PERMISSIONS, AdvancedPathLib::permsToUnix($mode)); $this->setMeta($meta); } //notify listeners on the parent directory $this->getParentFile()->fireEvent('directoryCreated', new FileEvent($this)); return true; } return false; }
/** * @param int $mode The mode. Default is 0777 - umask. * @return bool TRUE if the directory and all the needed parent ones have been * successfully created, FALSE otherwise * * Note: Some FTP servers seem to automatically create directories recursively while some * others don't, so the recursive process has to be forced in the following code. */ public function mkdirs($mode = null) { $parentFile = $this->getParentFile(); if (!$parentFile->exists()) { if (!$parentFile->mkdirs($mode)) { throw new EyeIOException('Unable to create directory ' . AdvancedPathLib::getURLForDisplay($parentFile->path) . '.'); } } $pathFromRoot = $this->getPathFromRoot(); $res = $this->getConnection(); try { if (ftp_mkdir($res, $pathFromRoot)) { $this->statsCache['isDirectory'] = true; $this->statsCache['isFile'] = false; $this->statsCache['isLink'] = false; $modeOk = false; if ($mode !== null) { $newPerms = ftp_chmod($res, $mode, $pathFromRoot); if ($newPerms) { $newPerms |= 0x4000; //directory bit value $this->statsCache['permissions'] = AdvancedPathLib::permsToUnix($newPerms); $modeOk = true; } } if (!$modeOk) { $this->fetchStats(); } return true; } } catch (EyeErrorException $e) { throw new EyeIOException('Unable to create directory ' . AdvancedPathLib::getURLForDisplay($this->path) . '.', 0, $e); } throw new EyeIOException('Unable to create directory ' . AdvancedPathLib::getURLForDisplay($this->path) . '.'); }
public function testMkdir() { /**** non-existing home dir ****/ $this->assertFalse(is_dir(USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeDirZ')); $file = FSI::getFile('home://~john/myHomeDirZ'); $this->assertNull($file->getMeta()); $this->assertTrue($file->mkdir()); $this->assertTrue(is_dir(USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeDirZ')); //check metadata $meta = $file->getMeta(); $this->assertNotNull($meta); $this->assertEquals('john', $meta->get(EyeosAbstractVirtualFile::METADATA_KEY_OWNER)); $this->assertEquals('users', $meta->get(EyeosAbstractVirtualFile::METADATA_KEY_GROUP)); $this->assertEquals(AdvancedPathLib::permsToUnix(0777 & ~$file->getUMask()), $meta->get(EyeosAbstractVirtualFile::METADATA_KEY_PERMISSIONS)); $file->delete(); /**** non-existing home dir (mode = 0751) ****/ $this->assertFalse(is_dir(USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeDirZ')); $file = FSI::getFile('home://~john/myHomeDirZ'); $this->assertNull($file->getMeta()); $this->assertTrue($file->mkdir(0751)); $this->assertTrue(is_dir(USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeDirZ')); //check metadata ( => rights !) $meta = $file->getMeta(); $this->assertNotNull($meta); $this->assertEquals('john', $meta->get(EyeosAbstractVirtualFile::METADATA_KEY_OWNER)); $this->assertEquals('users', $meta->get(EyeosAbstractVirtualFile::METADATA_KEY_GROUP)); $this->assertEquals(AdvancedPathLib::permsToUnix(0751), $meta->get(EyeosAbstractVirtualFile::METADATA_KEY_PERMISSIONS)); $file->delete(); /**** existing home dir ****/ $this->assertTrue(is_dir($this->fixture_dir1_path)); try { $this->fixture_dir1->mkdir(); $this->fail(); } catch (EyeIOException $e) { // normal situation } $this->assertTrue(is_dir($this->fixture_dir1_path)); //TODO: test sys files when metadata will be implemented for them }
public function testPermsToUnix() { $this->assertEquals('-rwxrwxrwx', AdvancedPathLib::permsToUnix(0777)); $this->assertEquals('----------', AdvancedPathLib::permsToUnix(0)); $this->assertEquals('-rwxr-xr-x', AdvancedPathLib::permsToUnix(0755)); $this->assertEquals('-r-xr--r--', AdvancedPathLib::permsToUnix(0544)); $this->assertEquals('-r----x--x', AdvancedPathLib::permsToUnix(0411)); }
/** * @return string The permissions of the file */ public function getPermissions($octal = true) { if (!$this->exists()) { throw new EyeFileNotFoundException('File ' . $this->path . ' does not exist.'); } if ($this->isDirectory()) { $perm = self::PERMISSIONS_MASK_DIR & ~$this->getUMask(); } else { if ($this->isLink()) { $perm = self::PERMISSIONS_VALUE_LINK; } else { $perm = self::PERMISSIONS_MASK_FILE & ~$this->getUMask(); } } if (!$octal) { $perm = AdvancedPathLib::permsToUnix($perm); } return $perm; }
/** * @param bool $octal TRUE to return permissions in octal form (755), * FALSE to return them in Unix form (rwxr-xr-x) * @return mixed The permissions of the file * @throws EyeStatFailedException */ public function getPermissions($octal = true) { $path = AdvancedPathLib::getPhpLocalHackPath($this->path); $perms = fileperms($path); if ($perms == false) { throw new EyeStatFailedException('Unable to fetch permissions for file ' . $this->path . '.'); } if (!$octal) { $perms = AdvancedPathLib::permsToUnix($perms); } return $perms; }