Example #1
0
 /** 
  * Check ownership/mode/privacy of repository 
  * 
  * @param Project $project The project to work on
  * 
  * @return boolean true if success
  */
 public function checkSVNMode(Project $project)
 {
     $unix_group_name = $project->getUnixNameMixedCase();
     $svnroot = $project->getSVNRootPath();
     $is_private = !$project->isPublic() || $project->isSVNPrivate();
     if ($is_private) {
         $perms = fileperms($svnroot);
         // 'others' should have no right on the repository
         if ($perms & 0x4 || $perms & 0x2 || $perms & 0x1 || $perms & 0x200) {
             $this->log("Restoring privacy on SVN dir: {$svnroot}", Backend::LOG_WARNING);
             $this->setSVNPrivacy($project, $is_private);
         }
     }
     // Sometimes, there might be a bad ownership on file (e.g. chmod failed, maintenance done as root...)
     $files_to_check = array('db/current', 'hooks/pre-commit', 'hooks/post-commit', 'db/rep-cache.db');
     $need_owner_update = false;
     foreach ($files_to_check as $file) {
         // Get file stat
         if (file_exists("{$svnroot}/{$file}")) {
             $stat = stat("{$svnroot}/{$file}");
             if ($stat['uid'] != $this->getHTTPUserUID() || $stat['gid'] != $project->getUnixGID()) {
                 $need_owner_update = true;
             }
         }
     }
     if ($need_owner_update) {
         $this->log("Restoring ownership on SVN dir: {$svnroot}", Backend::LOG_INFO);
         $this->recurseChownChgrp($svnroot, $this->getHTTPUser(), $unix_group_name);
         $this->chown($svnroot, $this->getHTTPUser());
         $this->chgrp($svnroot, $unix_group_name);
         system("chmod g+rw {$svnroot}");
     }
     return true;
 }