SymlinkDumper.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\Package;
  12. use Symfony\Component\Filesystem\Filesystem;
  13. use Composer\Util\Filesystem as ComposerFilesystem;
  14. use Symfony\Bridge\Doctrine\RegistryInterface;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. use Symfony\Component\Finder\Finder;
  17. use Packagist\WebBundle\Entity\Version;
  18. /**
  19. * @author Jordi Boggiano <j.boggiano@seld.be>
  20. */
  21. class SymlinkDumper
  22. {
  23. /**
  24. * Doctrine
  25. * @var RegistryInterface
  26. */
  27. protected $doctrine;
  28. /**
  29. * @var Filesystem
  30. */
  31. protected $fs;
  32. /**
  33. * @var ComposerFilesystem
  34. */
  35. protected $cfs;
  36. /**
  37. * @var string
  38. */
  39. protected $webDir;
  40. /**
  41. * @var string
  42. */
  43. protected $buildDir;
  44. /**
  45. * @var UrlGeneratorInterface
  46. */
  47. protected $router;
  48. /**
  49. * Data cache
  50. * @var array
  51. */
  52. private $rootFile;
  53. /**
  54. * Data cache
  55. * @var array
  56. */
  57. private $listings = array();
  58. /**
  59. * Data cache
  60. * @var array
  61. */
  62. private $individualFiles = array();
  63. /**
  64. * Modified times of individual files
  65. * @var array
  66. */
  67. private $individualFilesMtime = array();
  68. /**
  69. * Stores all the disk writes to be replicated in the second build dir after the symlink has been swapped
  70. * @var array
  71. */
  72. private $writeLog = array();
  73. /**
  74. * Generate compressed files.
  75. * @var int 0 disabled, 9 maximum.
  76. */
  77. private $compress;
  78. /**
  79. * Constructor
  80. *
  81. * @param RegistryInterface $doctrine
  82. * @param Filesystem $filesystem
  83. * @param UrlGeneratorInterface $router
  84. * @param string $webDir web root
  85. * @param string $targetDir
  86. * @param int $compress
  87. */
  88. public function __construct(RegistryInterface $doctrine, Filesystem $filesystem, UrlGeneratorInterface $router, $webDir, $targetDir, $compress)
  89. {
  90. $this->doctrine = $doctrine;
  91. $this->fs = $filesystem;
  92. $this->cfs = new ComposerFilesystem;
  93. $this->router = $router;
  94. $this->webDir = realpath($webDir);
  95. $this->buildDir = $targetDir;
  96. $this->compress = $compress;
  97. }
  98. /**
  99. * Dump a set of packages to the web root
  100. *
  101. * @param array $packageIds
  102. * @param Boolean $force
  103. * @param Boolean $verbose
  104. */
  105. public function dump(array $packageIds, $force = false, $verbose = false)
  106. {
  107. $cleanUpOldFiles = date('i') == 0;
  108. // prepare build dir
  109. $webDir = $this->webDir;
  110. $buildDirA = $this->buildDir.'/a';
  111. $buildDirB = $this->buildDir.'/b';
  112. // initialize
  113. $initialRun = false;
  114. if (!is_dir($buildDirA) || !is_dir($buildDirB)) {
  115. $initialRun = true;
  116. if (!$this->removeDirectory($buildDirA) || !$this->removeDirectory($buildDirB)) {
  117. throw new \RuntimeException('Failed to delete '.$buildDirA.' or '.$buildDirB);
  118. }
  119. $this->fs->mkdir($buildDirA);
  120. $this->fs->mkdir($buildDirB);
  121. }
  122. // set build dir to the not-active one
  123. if (realpath($webDir.'/p') === realpath($buildDirA)) {
  124. $buildDir = realpath($buildDirB);
  125. $oldBuildDir = realpath($buildDirA);
  126. } else {
  127. $buildDir = realpath($buildDirA);
  128. $oldBuildDir = realpath($buildDirB);
  129. }
  130. // copy existing stuff for smooth BC transition
  131. if ($initialRun && !$force) {
  132. if (!file_exists($webDir.'/p') || is_link($webDir.'/p')) {
  133. @rmdir($buildDir);
  134. @rmdir($oldBuildDir);
  135. throw new \RuntimeException('Run this again with --force the first time around to make sure it dumps all packages');
  136. }
  137. if ($verbose) {
  138. echo 'Copying existing files'.PHP_EOL;
  139. }
  140. foreach (array($buildDir, $oldBuildDir) as $dir) {
  141. $this->cloneDir($webDir.'/p', $dir);
  142. }
  143. }
  144. if ($verbose) {
  145. echo 'Web dir is '.$webDir.'/p ('.realpath($webDir.'/p').')'.PHP_EOL;
  146. echo 'Build dir is '.$buildDir.PHP_EOL;
  147. }
  148. // clean the build dir to start over if we are re-dumping everything
  149. if ($force) {
  150. // disable the write log since we copy everything at the end in forced mode
  151. $this->writeLog = false;
  152. if ($verbose) {
  153. echo 'Cleaning up existing files'.PHP_EOL;
  154. }
  155. if (!$this->clearDirectory($buildDir)) {
  156. return false;
  157. }
  158. }
  159. try {
  160. $modifiedIndividualFiles = array();
  161. $total = count($packageIds);
  162. $current = 0;
  163. $step = 50;
  164. while ($packageIds) {
  165. $dumpTime = new \DateTime;
  166. $packages = $this->doctrine->getRepository('PackagistWebBundle:Package')->getPackagesWithVersions(array_splice($packageIds, 0, $step));
  167. if ($verbose) {
  168. echo '['.sprintf('%'.strlen($total).'d', $current).'/'.$total.'] Processing '.$step.' packages'.PHP_EOL;
  169. }
  170. $current += $step;
  171. // prepare packages in memory
  172. foreach ($packages as $package) {
  173. $affectedFiles = array();
  174. $name = strtolower($package->getName());
  175. // clean up versions in individual files
  176. if (file_exists($buildDir.'/'.$name.'.files')) {
  177. $files = json_decode(file_get_contents($buildDir.'/'.$name.'.files'));
  178. foreach ($files as $file) {
  179. if (substr_count($file, '/') > 1) { // handle old .files with p/*/*.json paths
  180. $file = preg_replace('{^p/}', '', $file);
  181. }
  182. $this->loadIndividualFile($buildDir.'/'.$file, $file);
  183. if (isset($this->individualFiles[$file]['packages'][$name])) {
  184. unset($this->individualFiles[$file]['packages'][$name]);
  185. $modifiedIndividualFiles[$file] = true;
  186. }
  187. }
  188. }
  189. // (re)write versions in individual files
  190. foreach ($package->getVersions() as $version) {
  191. foreach (array_slice($version->getNames(), 0, 150) as $versionName) {
  192. if (!preg_match('{^[A-Za-z0-9_-][A-Za-z0-9_.-]*/[A-Za-z0-9_-][A-Za-z0-9_.-]*$}', $versionName) || strpos($versionName, '..')) {
  193. continue;
  194. }
  195. $file = $buildDir.'/'.$versionName.'.json';
  196. $key = $versionName.'.json';
  197. $this->dumpVersionToIndividualFile($version, $file, $key);
  198. $modifiedIndividualFiles[$key] = true;
  199. $affectedFiles[$key] = true;
  200. }
  201. }
  202. // store affected files to clean up properly in the next update
  203. $this->fs->mkdir(dirname($buildDir.'/'.$name));
  204. $this->writeFile($buildDir.'/'.$name.'.files', json_encode(array_keys($affectedFiles)));
  205. // update dump date
  206. $package->setDumpedAt($dumpTime);
  207. $this->doctrine->getManager()->flush($package);
  208. }
  209. unset($packages, $package, $version);
  210. $this->doctrine->getManager()->clear();
  211. if ($current % 250 === 0 || !$packageIds) {
  212. if ($verbose) {
  213. echo 'Dumping individual files'.PHP_EOL;
  214. }
  215. $this->dumpIndividualFiles($buildDir);
  216. }
  217. }
  218. // prepare individual files listings
  219. if ($verbose) {
  220. echo 'Preparing individual files listings'.PHP_EOL;
  221. }
  222. $safeFiles = array();
  223. $individualHashedListings = array();
  224. $finder = Finder::create()->files()->ignoreVCS(true)->name('*.json')->in($buildDir)->depth('1');
  225. foreach ($finder as $file) {
  226. // skip hashed files
  227. if (strpos($file, '$')) {
  228. continue;
  229. }
  230. $key = basename(dirname($file)).'/'.basename($file);
  231. if ($force && !isset($modifiedIndividualFiles[$key])) {
  232. continue;
  233. }
  234. // add hashed provider to listing
  235. $listing = $this->getTargetListing($file);
  236. $hash = hash_file('sha256', $file);
  237. $key = substr($key, 0, -5);
  238. $safeFiles[] = $key.'$'.$hash.'.json';
  239. $this->listings[$listing]['providers'][$key] = array('sha256' => $hash);
  240. $individualHashedListings[$listing] = true;
  241. }
  242. // prepare root file
  243. $rootFile = $buildDir.'/packages.json';
  244. $this->rootFile = array('packages' => array());
  245. $url = $this->router->generate('track_download', array('name' => 'VND/PKG'));
  246. $this->rootFile['notify'] = str_replace('VND/PKG', '%package%', $url);
  247. $this->rootFile['notify-batch'] = $this->router->generate('track_download_batch');
  248. $this->rootFile['providers-url'] = $this->router->generate('home') . 'p/%package%$%hash%.json';
  249. $this->rootFile['search'] = $this->router->generate('search', array('_format' => 'json')) . '?q=%query%';
  250. if ($verbose) {
  251. echo 'Dumping individual listings'.PHP_EOL;
  252. }
  253. // dump listings to build dir
  254. foreach ($individualHashedListings as $listing => $dummy) {
  255. list($listingPath, $hash) = $this->dumpListing($buildDir.'/'.$listing);
  256. $hashedListing = basename($listingPath);
  257. $this->rootFile['provider-includes']['p/'.str_replace($hash, '%hash%', $hashedListing)] = array('sha256' => $hash);
  258. $safeFiles[] = $hashedListing;
  259. }
  260. if ($verbose) {
  261. echo 'Dumping root'.PHP_EOL;
  262. }
  263. $this->dumpRootFile($rootFile);
  264. } catch (\Exception $e) {
  265. // restore files as they were before we started
  266. $this->cloneDir($oldBuildDir, $buildDir);
  267. throw $e;
  268. }
  269. try {
  270. if ($verbose) {
  271. echo 'Putting new files in production'.PHP_EOL;
  272. }
  273. // move away old files for BC update
  274. if ($initialRun && file_exists($webDir.'/p') && !is_link($webDir.'/p')) {
  275. rename($webDir.'/p', $webDir.'/p-old');
  276. }
  277. $this->switchActiveWebDir($webDir, $buildDir);
  278. } catch (\Exception $e) {
  279. @symlink($oldBuildDir, $webDir.'/p');
  280. throw $e;
  281. }
  282. try {
  283. if ($initialRun || !is_link($webDir.'/packages.json') || $force) {
  284. if ($verbose) {
  285. echo 'Writing/linking the packages.json'.PHP_EOL;
  286. }
  287. if (file_exists($webDir.'/packages.json')) {
  288. unlink($webDir.'/packages.json');
  289. }
  290. if (file_exists($webDir.'/packages.json.gz')) {
  291. unlink($webDir.'/packages.json.gz');
  292. }
  293. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  294. $sourcePath = $buildDir.'/packages.json';
  295. if (!copy($sourcePath, $webDir.'/packages.json')) {
  296. throw new \RuntimeException('Could not copy the packages.json file');
  297. }
  298. } else {
  299. $sourcePath = 'p/packages.json';
  300. if (!symlink($sourcePath, $webDir.'/packages.json')) {
  301. throw new \RuntimeException('Could not symlink the packages.json file');
  302. }
  303. if ($this->compress && !symlink($sourcePath.'.gz', $webDir.'/packages.json.gz')) {
  304. throw new \RuntimeException('Could not symlink the packages.json.gz file');
  305. }
  306. }
  307. }
  308. } catch (\Exception $e) {
  309. $this->switchActiveWebDir($webDir, $oldBuildDir);
  310. throw $e;
  311. }
  312. // clean up old dir if present on BC update
  313. if ($initialRun) {
  314. $this->removeDirectory($webDir.'/p-old');
  315. }
  316. // clean the old build dir if we re-dumped everything
  317. if ($force) {
  318. if ($verbose) {
  319. echo 'Cleaning up old build dir'.PHP_EOL;
  320. }
  321. if (!$this->clearDirectory($oldBuildDir)) {
  322. throw new \RuntimeException('Unrecoverable inconsistent state (old build dir could not be cleared), run with --force again to retry');
  323. }
  324. }
  325. // copy state to old active dir
  326. if ($force) {
  327. if ($verbose) {
  328. echo 'Copying new contents to old build dir to sync up'.PHP_EOL;
  329. }
  330. $this->cloneDir($buildDir, $oldBuildDir);
  331. } else {
  332. if ($verbose) {
  333. echo 'Replaying write log in old build dir'.PHP_EOL;
  334. }
  335. $this->copyWriteLog($buildDir, $oldBuildDir);
  336. }
  337. // clean up old files once an hour
  338. if (!$force && $cleanUpOldFiles) {
  339. if ($verbose) {
  340. echo 'Cleaning up old files'.PHP_EOL;
  341. }
  342. $this->cleanOldFiles($buildDir, $oldBuildDir, $safeFiles);
  343. }
  344. // TODO when a package is deleted, it should be removed from provider files, or marked for removal at least
  345. return true;
  346. }
  347. private function switchActiveWebDir($webDir, $buildDir)
  348. {
  349. $newLink = $webDir.'/p-new';
  350. $oldLink = $webDir.'/p';
  351. if (file_exists($newLink)) {
  352. unlink($newLink);
  353. }
  354. if (!symlink($buildDir, $newLink)) {
  355. throw new \RuntimeException('Could not symlink the build dir into the web dir');
  356. }
  357. if (!rename($newLink, $oldLink)) {
  358. throw new \RuntimeException('Could not replace the old symlink with the new one in the web dir');
  359. }
  360. }
  361. private function cloneDir($source, $target)
  362. {
  363. $this->removeDirectory($target);
  364. exec('cp -rpf '.escapeshellarg($source).' '.escapeshellarg($target), $output, $exit);
  365. if (0 !== $exit) {
  366. echo 'Warning, cloning a directory using the php fallback does not keep filemtime, invalid behavior may occur';
  367. $this->fs->mirror($source, $target, null, array('override' => true));
  368. }
  369. }
  370. private function cleanOldFiles($buildDir, $oldBuildDir, $safeFiles)
  371. {
  372. $finder = Finder::create()->directories()->ignoreVCS(true)->in($buildDir);
  373. foreach ($finder as $vendorDir) {
  374. $vendorFiles = Finder::create()->files()->ignoreVCS(true)
  375. ->name('/\$[a-f0-9]+\.json$/')
  376. ->date('until 10minutes ago')
  377. ->in((string) $vendorDir);
  378. foreach ($vendorFiles as $file) {
  379. $key = strtr(str_replace($buildDir.DIRECTORY_SEPARATOR, '', $file), '\\', '/');
  380. if (!in_array($key, $safeFiles, true)) {
  381. unlink((string) $file);
  382. if (file_exists($altDirFile = str_replace($buildDir, $oldBuildDir, (string) $file))) {
  383. unlink($altDirFile);
  384. }
  385. }
  386. }
  387. }
  388. // clean up old provider listings
  389. $finder = Finder::create()->depth(0)->files()->name('provider-*.json')->ignoreVCS(true)->in($buildDir)->date('until 10minutes ago');
  390. foreach ($finder as $provider) {
  391. $key = strtr(str_replace($buildDir.DIRECTORY_SEPARATOR, '', $provider), '\\', '/');
  392. if (!in_array($key, $safeFiles, true)) {
  393. $path = (string) $provider;
  394. unlink($path);
  395. if (file_exists($path.'.gz')) {
  396. unlink($path.'.gz');
  397. }
  398. if (file_exists($altDirFile = str_replace($buildDir, $oldBuildDir, $path))) {
  399. unlink($altDirFile);
  400. if (file_exists($altDirFile.'.gz')) {
  401. unlink($altDirFile.'.gz');
  402. }
  403. }
  404. }
  405. }
  406. // clean up old root listings
  407. $finder = Finder::create()->depth(0)->files()->name('packages.json-*')->ignoreVCS(true)->in($buildDir)->date('until 10minutes ago');
  408. foreach ($finder as $rootFile) {
  409. $path = (string) $rootFile;
  410. unlink($path);
  411. if (file_exists($path.'.gz')) {
  412. unlink($path.'.gz');
  413. }
  414. if (file_exists($altDirFile = str_replace($buildDir, $oldBuildDir, $path))) {
  415. unlink($altDirFile);
  416. if (file_exists($altDirFile.'.gz')) {
  417. unlink($altDirFile.'.gz');
  418. }
  419. }
  420. }
  421. }
  422. private function dumpRootFile($file)
  423. {
  424. // sort all versions and packages to make sha1 consistent
  425. ksort($this->rootFile['packages']);
  426. ksort($this->rootFile['provider-includes']);
  427. foreach ($this->rootFile['packages'] as $package => $versions) {
  428. ksort($this->rootFile['packages'][$package]);
  429. }
  430. if (file_exists($file)) {
  431. $timedFile = $file.'-'.time();
  432. rename($file, $timedFile);
  433. if (file_exists($file.'.gz')) {
  434. rename($file.'.gz', $timedFile.'.gz');
  435. }
  436. }
  437. $json = json_encode($this->rootFile);
  438. $time = time();
  439. $this->writeFile($file, $json, $time);
  440. if ($this->compress) {
  441. $this->writeFile($file . '.gz', gzencode($json, $this->compress), $time);
  442. }
  443. }
  444. private function dumpListing($path)
  445. {
  446. $key = basename($path);
  447. // sort files to make hash consistent
  448. ksort($this->listings[$key]['providers']);
  449. $json = json_encode($this->listings[$key]);
  450. $hash = hash('sha256', $json);
  451. $path = substr($path, 0, -5) . '$' . $hash . '.json';
  452. $time = time();
  453. if (!file_exists($path)) {
  454. $this->writeFile($path, $json, $time);
  455. if ($this->compress) {
  456. $this->writeFile($path . '.gz', gzencode($json, $this->compress), $time);
  457. }
  458. }
  459. return array($path, $hash);
  460. }
  461. private function loadIndividualFile($path, $key)
  462. {
  463. if (isset($this->individualFiles[$key])) {
  464. return;
  465. }
  466. if (file_exists($path)) {
  467. $this->individualFiles[$key] = json_decode(file_get_contents($path), true);
  468. $this->individualFilesMtime[$key] = filemtime($path);
  469. } else {
  470. $this->individualFiles[$key] = array();
  471. $this->individualFilesMtime[$key] = 0;
  472. }
  473. }
  474. private function dumpIndividualFiles($buildDir)
  475. {
  476. // dump individual files to build dir
  477. foreach ($this->individualFiles as $file => $dummy) {
  478. $this->dumpIndividualFile($buildDir.'/'.$file, $file);
  479. }
  480. $this->individualFiles = array();
  481. $this->individualFilesMtime = array();
  482. }
  483. private function dumpIndividualFile($path, $key)
  484. {
  485. // sort all versions and packages to make sha1 consistent
  486. ksort($this->individualFiles[$key]['packages']);
  487. foreach ($this->individualFiles[$key]['packages'] as $package => $versions) {
  488. ksort($this->individualFiles[$key]['packages'][$package]);
  489. }
  490. $this->fs->mkdir(dirname($path));
  491. $json = json_encode($this->individualFiles[$key]);
  492. $this->writeFile($path, $json, $this->individualFilesMtime[$key]);
  493. // write the hashed provider file
  494. $hashedFile = substr($path, 0, -5) . '$' . hash('sha256', $json) . '.json';
  495. $this->writeFile($hashedFile, $json);
  496. }
  497. private function dumpVersionToIndividualFile(Version $version, $file, $key)
  498. {
  499. $this->loadIndividualFile($file, $key);
  500. $data = $version->toArray();
  501. $data['uid'] = $version->getId();
  502. $this->individualFiles[$key]['packages'][strtolower($version->getName())][$version->getVersion()] = $data;
  503. $timestamp = $version->getReleasedAt() ? $version->getReleasedAt()->getTimestamp() : time();
  504. if (!isset($this->individualFilesMtime[$key]) || $this->individualFilesMtime[$key] < $timestamp) {
  505. $this->individualFilesMtime[$key] = $timestamp;
  506. }
  507. }
  508. private function clearDirectory($path)
  509. {
  510. if (!$this->removeDirectory($path)) {
  511. echo 'Could not remove the build dir entirely, aborting';
  512. return false;
  513. }
  514. $this->fs->mkdir($path);
  515. return true;
  516. }
  517. private function removeDirectory($path)
  518. {
  519. $retries = 5;
  520. do {
  521. if (!$this->cfs->removeDirectory($path)) {
  522. usleep(200);
  523. }
  524. clearstatcache();
  525. } while (is_dir($path) && $retries--);
  526. return !is_dir($path);
  527. }
  528. private function getTargetListingBlocks($now)
  529. {
  530. $blocks = array();
  531. // monday last week
  532. $blocks['latest'] = strtotime('monday last week', $now);
  533. $month = date('n', $now);
  534. $month = ceil($month / 3) * 3 - 2; // 1 for months 1-3, 10 for months 10-12
  535. $block = new \DateTime(date('Y', $now).'-'.$month.'-01'); // 1st day of current trimester
  536. // split last 12 months in 4 trimesters
  537. for ($i=0; $i < 4; $i++) {
  538. $blocks[$block->format('Y-m')] = $block->getTimestamp();
  539. $block->sub(new \DateInterval('P3M'));
  540. }
  541. $year = (int) $block->format('Y');
  542. while ($year >= 2013) {
  543. $blocks[''.$year] = strtotime($year.'-01-01');
  544. $year--;
  545. }
  546. return $blocks;
  547. }
  548. private function getTargetListing($file)
  549. {
  550. static $blocks;
  551. if (!$blocks) {
  552. $blocks = $this->getTargetListingBlocks(time());
  553. }
  554. $mtime = filemtime($file);
  555. foreach ($blocks as $label => $block) {
  556. if ($mtime >= $block) {
  557. return "provider-${label}.json";
  558. }
  559. }
  560. return "provider-archived.json";
  561. }
  562. private function writeFile($path, $contents, $mtime = null)
  563. {
  564. file_put_contents($path, $contents);
  565. if ($mtime !== null) {
  566. touch($path, $mtime);
  567. }
  568. if (is_array($this->writeLog)) {
  569. $this->writeLog[$path] = array($contents, $mtime);
  570. }
  571. }
  572. private function copyWriteLog($from, $to)
  573. {
  574. foreach ($this->writeLog as $path => $op) {
  575. $path = str_replace($from, $to, $path);
  576. $this->fs->mkdir(dirname($path));
  577. file_put_contents($path, $op[0]);
  578. if ($op[1] !== null) {
  579. touch($path, $op[1]);
  580. }
  581. }
  582. }
  583. }