Commit:    0d9375dff4ce3313c6e90a78ebfc5ad79b3c5f57
Author:    Anatol Belski <[email protected]>         Tue, 12 May 2015 16:15:35 +0200
Parents:   33efad48308cdc8c9e92449557bca3b60001e945
Branches:  master pecl_legacy

Link:       
http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=0d9375dff4ce3313c6e90a78ebfc5ad79b3c5f57

Log:
implementation cleanups and jobs creation implementation

Changed paths:
  M  client/include/PickleDb.php
  M  client/include/PickleJob.php
  M  client/include/PickleWeb.php
  M  client/script/pickle_ctl.php


Diff:
diff --git a/client/include/PickleDb.php b/client/include/PickleDb.php
index 59c9358..b30b03b 100644
--- a/client/include/PickleDb.php
+++ b/client/include/PickleDb.php
@@ -59,7 +59,7 @@ class PickleDb extends \SQLite3
                        $this->createDir($dir);
                }
 
-               return strlen($data) == file_put_contents($fname, $data);
+               return strlen($data) == file_put_contents($fname, $data, 
LOCK_EX);
        }
 
        public function getUriJson($uri)
diff --git a/client/include/PickleJob.php b/client/include/PickleJob.php
index 506fcac..3b2b328 100644
--- a/client/include/PickleJob.php
+++ b/client/include/PickleJob.php
@@ -16,16 +16,30 @@ class PickleJob
                $this->job_dir = $job_dir;
        }
 
-       public function add($sha, $name, $uri)
+       public function add(array $tag)
        {
-               $fn = "{$this->job_dir}/$sha.job";
+               if (!isset($tag["support"]["source"])) {
+                       throw new \Exception("Tag source location isn't set, no 
jub created for '$tag[name]-$tag[version]'");
+               }
+
                $data = array(
-                       "name" => $name,
-                       "hash" => $sha,
-                       "uri"  => $uri,
+                       "name" => $tag["name"],
+                       "version" => $tag["version"],
+                       "src"  => $tag["support"]["source"],
                        "status" => "new",
                );
 
+               $tmp = tempnam($this->job_dir, $tag["name"]);
+               if (false === $tmp) {
+                       throw new \Exception("Failed to create temporary job 
file");
+               }
+
+               $fn  = "$tmp.job";
+
+               if (!rename($tmp, $fn)) {
+                       throw new \Exception("Failed to create job file");
+               }
+
                $this->save($fn, $data);
        }
 
@@ -33,7 +47,7 @@ class PickleJob
        {
                $json = json_encode($data, JSON_PRETTY_PRINT);
 
-               if (strlen($json) != file_put_contents($fn, $json)) {
+               if (strlen($json) != file_put_contents($fn, $json, LOCK_EX)) {
                        throw new \Exception("Error while writing data to 
'$fn'");
                }
        }
diff --git a/client/include/PickleWeb.php b/client/include/PickleWeb.php
index b9217a7..2eace71 100644
--- a/client/include/PickleWeb.php
+++ b/client/include/PickleWeb.php
@@ -142,6 +142,17 @@ class PickleWeb
                return true;
        }
 
+       protected function isValidTag(array $tag)
+       {
+               /* XXX raise some errors on this, or be more verbose at least 
??? */
+               return isset($tag["name"]) &&
+                       !empty($tag["name"]) &&
+                       isset($tag["version"]) &&
+                       !empty($tag["version"]) &&
+                       isset($tag["support"]["source"]) &&
+                       !empty($tag["support"]["source"]) /* XXX might check at 
least the URL format */;
+       }
+
        public function diffTags(array $remote, array $local)
        {
                $ret = array();
@@ -151,6 +162,9 @@ class PickleWeb
                } else if (empty($local) || !isset($local["packages"])) {
                        foreach ($remote["packages"] as $name => $tags) {
                                foreach ($tags as $version => $data) {
+                                       if (preg_match(",master,", $version) || 
!$this->isValidTag($data)) {
+                                               continue;
+                                       }
                                        /* $version is from the tag name, be 
strict and use the oone from the actual tag data*/
                                        if ($this->isUniqueTag($name, 
$data["version"], $ret)) {
                                                $ret[] = $data;
@@ -168,6 +182,9 @@ class PickleWeb
                        }
                        
                        foreach ($tags as $version => $data) {
+                               if (preg_match(",master,", $version) || 
!$this->isValidTag($data)) {
+                                       continue;
+                               }
                                if (!isset($local["packages"][$name][$version]) 
&& $this->isUniqueTag($name, $data["version"], $ret)) {
                                        $ret[] = $data;
                                }
diff --git a/client/script/pickle_ctl.php b/client/script/pickle_ctl.php
index 1a27a8c..7040eab 100644
--- a/client/script/pickle_ctl.php
+++ b/client/script/pickle_ctl.php
@@ -34,12 +34,13 @@ if ($_SERVER['argc'] <= 1 || $help_cmd) {
 
 if ($sync_cmd) {
 
-       $jobs = new rm\PickleJob($job_dir);
-
-       /* XXX handle the finished jobs first. */
        
 
        try {
+               $aa = new rm\PickleJob($job_dir);
+               /* XXX handle the finished jobs first. */
+               // $aa->cleanup();
+
                $pw = new rm\PickleWeb($sync_host, new rm\PickleDb($db_dir));
 
                if (!$pw->updatesAvailable()) {
@@ -48,13 +49,15 @@ if ($sync_cmd) {
                }
 
                $news = (array)$pw->getNewTags();
+
+               foreach ($news as $job) {
+                       $aa->add($job);
+               }
        } catch (Exception $e) {
                echo $e->getMessage() . "\n";
                exit(3);
        }
 
-       var_dump($news);
-
 }


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to