From a5afa11cff5673c331c4249b73814858b5ad351c Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 14 Sep 2017 18:49:14 +0200 Subject: [PATCH] Integrate locking into the dep update process --- .../libsdk/SDK/Build/Dependency/Manager.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/php/libsdk/SDK/Build/Dependency/Manager.php b/lib/php/libsdk/SDK/Build/Dependency/Manager.php index 1febd42..08144c3 100644 --- a/lib/php/libsdk/SDK/Build/Dependency/Manager.php +++ b/lib/php/libsdk/SDK/Build/Dependency/Manager.php @@ -2,7 +2,7 @@ namespace SDK\Build\Dependency; -use SDK\{Config, Cache, Exception, FileOps}; +use SDK\{Config, Cache, Exception, FileOps, Lock}; class Manager { @@ -39,7 +39,7 @@ class Manager public function updatesAvailable() : bool {/*{{{*/ - return $this->series->updatesAvailable(); + return $this->series->updatesAvailable() || !file_exists(Config::getDepsLocalPath()); }/*}}}*/ /* FIXME implement rollback */ @@ -50,6 +50,14 @@ class Manager $msg .= "No updates are available"; return; } + + $lock = new Lock(Config::getDepsLocalPath(), false); + if (!$lock->exclusive()) { + $msg .= "Another process is updating same dependency path. I'm just going to wait for it to finish and then exit."; + $lock->exclusive(true); + unset($lock); + return; + } } $series_data = $this->series->getData(); @@ -86,10 +94,16 @@ class Manager /* 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}'"); } } @@ -97,6 +111,9 @@ class Manager $up = dirname($this->path); if (!file_exists($up)) { if (!$this->md($up)) { + if (!$force) { + unset($lock); + } throw new Exception("Unable to create '{$this->path}'"); } } @@ -118,6 +135,10 @@ class Manager } else { $msg .= "No backup was created."; } + + if (!$force) { + unset($lock); + } }/*}}}*/ }