Each repository ID should increment by between 2^16 and 2^24 to avoid easy guessing
[phorkie.git] / src / phorkie / Repositories.php
index 729ff23afbab88e5664d45fa6330016388b68532..7ed3188e383ec61f5bb11f2cf05496d6bc12abc4 100644 (file)
@@ -23,16 +23,16 @@ class Repositories
             }
         );
         sort($dirs, SORT_NUMERIC);
-        $n = end($dirs) + 1;
+        $n = end($dirs) + mt_rand(65536, 16777216);
 
         chdir($this->workDir);
         $dir = $this->workDir . '/' . $n . '/';
-        mkdir($dir, 0777);//FIXME
+        mkdir($dir, fileperms($this->workDir) & 0777);
         $r = new Repository();
         $r->id = $n;
         $r->workDir = $dir;
         $r->gitDir = $this->gitDir . '/' . $n . '.git/';
-        mkdir($r->gitDir, 0777);//FIXME
+        mkdir($r->gitDir, fileperms($this->gitDir) & 0777);
 
         return $r;
     }
@@ -65,7 +65,16 @@ class Repositories
         $repos = array();
         foreach ($some as $oneDir) {
             $r = new Repository();
-            $r->loadById(substr($oneDir, 0, -4));
+            try {
+                $r->loadById(substr($oneDir, 0, -4));
+            } catch (\VersionControl_Git_Exception $e) {
+                if (strpos($e->getMessage(), 'does not have any commits') !== false) {
+                    //the git repo is broken as the initial commit
+                    // has not been finished
+                    continue;
+                }
+                throw $e;
+            }
             $repos[] = $r;
         }
         return array($repos, count($dirs), $page);