/** * Uploades files and creates directories. * @param string[] relative paths, starts with / * @return void */ private function uploadPaths(array $paths) { $prevDir = NULL; foreach ($paths as $num => $path) { $remotePath = $this->remoteDir . $path; $isDir = substr($remotePath, -1) === '/'; $remoteDir = $isDir ? substr($remotePath, 0, -1) : str_replace('\\', '/', dirname($remotePath)); if ($remoteDir !== $prevDir) { $prevDir = $remoteDir; $this->server->createDir($remoteDir); } if ($isDir) { $this->writeProgress($num + 1, count($paths), $path, NULL, 'green'); continue; } $localFile = $this->preprocess($path); if ($localFile !== $this->localDir . $path) { $path .= ' (filters applied)'; } $this->server->writeFile($localFile, $remotePath . self::TEMPORARY_SUFFIX, function ($percent) use($num, $paths, $path) { $this->writeProgress($num + 1, count($paths), $path, $percent, 'green'); }); $this->writeProgress($num + 1, count($paths), $path, NULL, 'green'); } }
/** * Uploades files. * @return void */ private function uploadFiles(array $files) { $root = $this->server->getDir(); $prevDir = NULL; $toRename = []; foreach ($files as $num => $file) { $remoteFile = $root . $file; $isDir = substr($remoteFile, -1) === '/'; $remoteDir = $isDir ? substr($remoteFile, 0, -1) : str_replace('\\', '/', dirname($remoteFile)); if ($remoteDir !== $prevDir) { $prevDir = $remoteDir; $this->server->createDir($remoteDir); } if ($isDir) { $this->writeProgress($num + 1, count($files), $file, NULL, 'green'); continue; } $localFile = $this->preprocess($orig = $this->local . $file); if (realpath($orig) !== $localFile) { $file .= ' (filters applied)'; } $toRename[] = $remoteFile; $this->server->writeFile($localFile, $remoteFile . self::TEMPORARY_SUFFIX, function ($percent) use($num, $files, $file) { $this->writeProgress($num + 1, count($files), $file, $percent, 'green'); }); $this->writeProgress($num + 1, count($files), $file, NULL, 'green'); } $this->logger->log("\nRenaming:"); foreach ($toRename as $num => $file) { $this->writeProgress($num + 1, count($toRename), "Renaming {$file}", NULL, 'olive'); $this->server->renameFile($file . self::TEMPORARY_SUFFIX, $file); } }