Integrate locking into the dep update process

This commit is contained in:
Anatol Belski 2017-09-14 18:49:14 +02:00
Родитель 6b58f91d9d
Коммит a5afa11cff
1 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -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);
}
}/*}}}*/
}