Пример #1
0
 /**
  * Returns the name of a file that doesn't yet exist in this directory
  *
  * Without a prefix or extension, this will create a filename 15 characters
  * long. If you change the $moreEntropy flag to true, the result will be
  * 25 characters
  *
  * @param String $prefix A prefix to attach to the file name
  * @param String $extension The extension the file should have
  * @param Boolean $moreEntropy Increases the length of the generated filename
  * @return \r8\FileSys\File
  */
 public function getUniqueFile($prefix = null, $extension = null, $moreEntropy = FALSE)
 {
     if (!$this->dirExists()) {
         throw new \r8\Exception\Variable("Dir", "No directory has been set for this instance");
     }
     $file = new \r8\FileSys\File();
     $file->setDir($this->getRawDir());
     if (!\r8\isVague($extension)) {
         $file->setExt($extension);
     }
     $prefix = \r8\isVague($prefix) ? null : (string) $prefix;
     $moreEntropy = (bool) $moreEntropy;
     do {
         if ($moreEntropy) {
             $uniq = md5(uniqid(null, true));
         } else {
             $uniq = substr(md5(uniqid()), 0, 15);
         }
         $file->setFileName($prefix . $uniq);
     } while ($file->exists());
     return $file;
 }
Пример #2
0
    }
    $result = system("cp -R " . escapeshellarg($base . $source) . " " . escapeshellarg($dest->getSubPath($destination)->getPath()));
    if ($result === FALSE) {
        die("Failed");
    }
    echo "complete\n";
}
// Remove the config file from pooled directory
if ($dest->contains("tests/config.php")) {
    $dest->getSubPath("tests/config.php")->delete();
    echo "test config file deleted\n";
}
$zipFile = new \r8\FileSys\File($base . "tools/RoundEights-" . r8_VERSION . ".zip");
$targzFile = new \r8\FileSys\File($base . "tools/RoundEights-" . r8_VERSION . ".tar.gz");
if ($zipFile->exists()) {
    echo "Removing existing zip file\n";
    $zipFile->delete();
}
if ($targzFile->exists()) {
    echo "Removing existing tar.gz file\n";
    $targzFile->delete();
}
// Create the archives archive
echo "Creating zip archive\n";
system("cd " . escapeshellarg($tempDir) . "; " . "zip -r " . escapeshellarg($zipFile->getPath()) . " " . escapeshellarg("RoundEights"));
echo "Creating tar.gz archive\n";
system("cd " . escapeshellarg($tempDir) . "; " . "tar -cvzf " . escapeshellarg($targzFile->getPath()) . " " . escapeshellarg("RoundEights"));
// Purge and remove the temporary dir
echo "Removing temporary directory\n";
$tempDir->purge()->delete();
echo "End of script\n";
Пример #3
0
 public function testExists()
 {
     $file = new \r8\FileSys\File($this->file);
     $this->assertTrue($file->exists());
     $file = new \r8\FileSys\File(__DIR__);
     $this->assertFalse($file->exists());
     $file = new \r8\FileSys\File("/path/to/missing/file");
     $this->assertFalse($file->exists());
 }