function testSyncDir() { if (file_exists(__DIR__ . "/synctest_copy")) { ZipDeploy::delTree(__DIR__ . "/synctest_copy"); } $dirSync = new DirSync(__DIR__ . "/synctest", __DIR__ . "/synctest_copy"); $dirSync->sync(); $this->assertTrue(file_exists(__DIR__ . "/synctest_copy")); $this->assertTrue(file_exists(__DIR__ . "/synctest_copy/file.txt")); $this->assertTrue(file_exists(__DIR__ . "/synctest_copy/another_file.txt")); file_put_contents(__DIR__ . "/synctest_copy/removeme.txt", "dummy"); file_put_contents(__DIR__ . "/synctest_copy/some_dir/removeme_too.txt", "dummy"); file_put_contents(__DIR__ . "/synctest_copy/some_dir/keepme.txt", "dummy"); $dirSync = new DirSync(__DIR__ . "/synctest", __DIR__ . "/synctest_copy"); $dirSync->addKeep("some_dir/keepme.txt"); $dirSync->sync(); $this->assertFalse(file_exists(__DIR__ . "/synctest_copy/removeme.txt")); $this->assertFalse(file_exists(__DIR__ . "/synctest_copy/some_dir/removeme_too.txt")); $this->assertTrue(file_exists(__DIR__ . "/synctest_copy/some_dir/keepme.txt")); if (file_exists(__DIR__ . "/synctest_copy")) { ZipDeploy::delTree(__DIR__ . "/synctest_copy"); } }
/** * Dispatch target. */ private function dispatchTarget() { $targetName = $_REQUEST["target"]; $target = $this->targetsByName[$targetName]; if (!$target) { throw new Exception("No such target: " . $targetName); } $target->authenicate(); if (sizeof($_FILES)) { $keys = array_keys($_FILES); $key = $keys[0]; $content = file_get_contents($_FILES[$key]["tmp_name"]); } else { $content = file_get_contents($this->inputFileName); } if (!$content || !strlen($content)) { throw new Exception("No POST input."); } $putRes = file_put_contents($this->tmpZipFileName, $content); if (!$putRes) { throw new Exception("unable to input file: " . print_r(error_get_last(), TRUE)); } $zip = new ZipArchive(); $openRes = $zip->open($this->tmpZipFileName); if ($openRes !== TRUE) { throw new Exception("open failed: " . $openRes); } if (file_exists($this->tempDir)) { self::delTree($this->tempDir); } $extractRes = $zip->extractTo($this->tempDir); if (!$extractRes) { throw new Exception("unable to extract " . print_r(error_get_last(), TRUE)); } $zip->close(); $sync = new DirSync($this->tempDir . "/" . $target->getZipDir(), $target->getTargetDir()); foreach ($target->getKeeps() as $keep) { $sync->addKeep($keep); } //$sync->addKeep("hello"); $sync->sync(); if (file_exists($this->tempDir)) { self::delTree($this->tempDir); } self::delTree($this->tmpZipFileName); echo "OK"; }