InDefero

Sign in or create your account | Project List | Help

InDefero Commit Details

Date:2009-06-19 16:44:35 (8 months 21 days ago)
Author:Mehdi Kabab
Commit:e235242ea6b51e8e70767814bb1acbb0e144b42a
Message:Fixed issue 204, deleting a project does not remove the repository

Files: doc/syncgit.mdtext (1 diff)
src/IDF/Plugin/SyncGit/Cron.php (2 diffs)

Change Details

doc/syncgit.mdtext
7070    $cfg['idf_plugin_syncgit_path_gitserve'] = '/home/www/indefero/scripts/gitserve.py'; # yes .py
7171    $cfg['idf_plugin_syncgit_path_authorized_keys'] = '/home/git/.ssh/authorized_keys';
7272    $cfg['idf_plugin_syncgit_sync_file'] = '/tmp/SYNC-GIT';
73    # Remove the git repositories which do not have a corresponding project
74    # This is run at cron time
75    $cfg['idf_plugin_syncgit_remove_orphans'] = false;
7376
7477When someone will change his SSH key or add a new one, the
7578`/tmp/SYNC-GIT` file will be created. The cron job
src/IDF/Plugin/SyncGit/Cron.php
7070    }
7171
7272    /**
73     * Remove orphan repositories.
74     */
75    public static function removeOrphanRepositories()
76    {
77        $path = Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories');
78        if (!is_dir($path) || is_link($path)) {
79            throw new Pluf_Exception_SettingError(sprintf(
80                'Directory %s does not exist! Setting "idf_plugin_syncgit_base_repositories not set.',
81                $path));
82        }
83        if (!is_writable($path)) {
84            throw new Exception(sprintf('Repository %s is not writable.', $path));
85        }
86        $projects = array();
87        foreach (Pluf::factory('IDF_Project')->getList() as $project) {
88            $projects[] = $project->shortname;
89        }
90        unset($project);
91        $it = new DirectoryIterator($path);
92        $orphans = array();
93        while ($it->valid()) {
94            if (!$it->isDot() && $it->isDir() && !in_array(basename($it->getFileName(), '.git'), $projects)) {
95                $orphans[] = $it->getPathName();
96            }
97            $it->next();
98        }
99        if (count($orphans)) {
100            $cmd = Pluf::f('idf_exec_cmd_prefix', '').'rm -rf '.implode(' ', $orphans);
101            exec($cmd);
102            while (list(, $project) = each($orphans)) {
103                if (is_dir($project)) {
104                    throw new Exception(sprintf('Cannot remove %s directory.', $project));
105                }
106            }
107        }
108    }
109
110    /**
73111     * Check if a sync is needed.
74112     *
75113     */
...... 
79117            @unlink(Pluf::f('idf_plugin_syncgit_sync_file'));
80118            self::sync();
81119            self::markExport();
120            if (Pluf::f('idf_plugin_syncgit_remove_orphans', false)) {
121                self::removeOrphanRepositories();
122            }
82123        }
83124    }
84125}

Archive Download the corresponding diff file

Branches:
dev
master
newdiff
svn