public function performUpdate()

in lib/php/libsdk/SDK/Build/Dependency/Manager.php [54:151]


	public function performUpdate(string &$msg = NULL, bool $force = false, bool $backup = true) : void
	{/*{{{*/
		if (!$force) {
			if (!$this->updatesAvailable()) {
				$msg .= "No updates are available";
				return;
			}

			$lock = new Lock(Config::getDepsLocalPath());
			if (!$lock->locked()) {
				$msg .= "Dependencies was updated by another process.";
				echo "Another process is updating same dependency path. I'm just going to wait for it to finish and then exit.", PHP_EOL;
				$lock->exclusive(true);
				unset($lock);
				return;
			}
		}

		$series_data = $this->series->getData();

		$tmp_dir = $this->md("", true);
		$tmp_dir_packs = $this->md($tmp_dir . DIRECTORY_SEPARATOR . "packs");
		$tmp_dir_deps = $this->md($tmp_dir . DIRECTORY_SEPARATOR . "deps");

		foreach ($series_data as $item) {
			echo "Processing package $item", PHP_EOL;
			$pkg = new Package($item, $this->series, $this->fetcher);

			$pkg->retrieve($tmp_dir_packs);
			$pkg->unpack($tmp_dir_deps);
			$pkg->cleanup();

			unset($pkg);
		}

		/* Clear, it is an extra handling. So far it's the only case, doing it this way. And, we have
			no package definitions ATM to handle it otherwise. */
		$extra = $tmp_dir_deps . DIRECTORY_SEPARATOR . "openssl.cnf";
		if (file_exists($extra)) {
			$tdir = $tmp_dir_deps . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "ssl";

			$this->md($tdir);
			$this->mv($extra, $tdir . DIRECTORY_SEPARATOR . "openssl.cnf");
		}

		if (file_exists($this->path)) {
			if ($backup) {
				$suffix = date("YmdHi");
				$new_path = "{$this->path}.$suffix";

				/* This is fine, it's gonna be on the same drive. */
				if (!$this->mv($this->path, $new_path)) {
					if (!$force) {
						unset($lock);
					}
					throw new Exception("Unable to rename '{$this->path}' to '$new_path'");
				}
			} else {
				if (!$this->rm($this->path)) {
					if (!$force) {
						unset($lock);
					}
					throw new Exception("Unable to remove the current dependency dir at '{$this->path}'");
				}
			}
		} else {
			$up = dirname($this->path);
			if (!file_exists($up)) {
				if (!$this->md($up)) {
					if (!$force) {
						unset($lock);
					}
					throw new Exception("Unable to create '{$this->path}'");
				}
			}
		}

		$this->mv($tmp_dir_deps, $this->path);

		$this->rm($tmp_dir_packs);
		$this->rm($tmp_dir);

		$this->series->cache();

		/* save new series file, move the updated deps and backup the old ones, cleanup.*/
		$msg .= "Updates performed successfully. " . PHP_EOL;
		if ($backup) {
			if (isset($new_path)) {
				$msg .= "Old dependencies backed up into '$new_path'.";
			}
		} else {
			$msg .= "No backup was created.";
		}

		if (!$force) {
			unset($lock);
		}
	}/*}}}*/