/** * @param $targetDir * @param \PhotoOrganize\Domain\Ports\Filesystem $fs * @return string */ public function createSymlink($targetDir, Filesystem $fs) { $dir = $this->getDatePath(); $fs->mkdir("{$targetDir}/{$dir}"); $fs->symlink($this->file->getRealPath(), "{$targetDir}/{$this->getSymlinkTarget()}", true); return "{$targetDir}/{$this->getSymlinkTarget()}"; }
/** * @param $sourceDir * @param $targetDir * @param $isDryRun * @return Observable\ConnectableObservable */ public function execute($sourceDir, $targetDir, $isDryRun) { $files = Observable::fromIterator($this->filesystem->ls($sourceDir)); $filesWithDate = $this->fileWithDateRepository->extractDateFrom($files)->publish(); $symlinkCommands = $this->symlinkCommandRepository->createSymlinkCommands($filesWithDate, new Path($targetDir)); $summary = $this->summaryRepository->summarize($filesWithDate); $symlinkCommands->merge($summary)->subscribe($this->output); if (!$isDryRun) { $symlinkCommands->subscribeCallback(function (SymlinkCommand $cmd) { $this->output->onNext("write file"); $this->linkRepository->createLink($cmd->getSource(), $cmd->getTarget()); }); } $filesWithDate->connect(); }
/** * @param Path $source original file * @param Path $target new file */ public function createLink(Path $source, Path $target) { $this->fs->symlink($source->getValue(), $target->getValue(), true); }