diff --git a/DEVNOTES.md b/DEVNOTES.md index 648a080..0dbc3b2 100644 --- a/DEVNOTES.md +++ b/DEVNOTES.md @@ -2,16 +2,16 @@ ### TODOs -* integrate webhook support (callback to accept POST, figure out repo, run git fetch on it), check security / DOS +* integrate webhook support (callback to accept POST, figure out repo, run git fetch on it) --> see [redmine_github_hook](https://github.com/koppen/redmine_github_hook) meanwhile +* check security / DOS * key management (currently user needs to populate ~/.ssh/* config files manually) -* cleanup cloned repos on Repository#destroy * make sure git fetch doesn't hang (timeout, background, local vs remote fetch interference) * last fetched status, clearer error handling -* on plugin uninstall, Redmine will crash (rails hates it when you remove model classes) -* (provide a rake command to convert to Git type) * initialize_clone should only run on new objects (since only "Main repository" is editable) * key handling -* removing the plugin, what happens to records? +* on plugin uninstall, Redmine will crash (rails hates it when you remove model classes) + - provide a rake command to convert to Git type + - removing the plugin, what happens to records? * conversion of legacy records diff --git a/app/models/repository/git_remote.rb b/app/models/repository/git_remote.rb index f5c0b2d..35173a6 100644 --- a/app/models/repository/git_remote.rb +++ b/app/models/repository/git_remote.rb @@ -10,14 +10,7 @@ class Repository::GitRemote < Repository::Git PATH_PREFIX = PLUGIN_ROOT + "/repos/" before_validation :initialize_clone - - # TODO: figure out how to do this safely (if at all) - # before_deletion :rm_removed_repo - # def rm_removed_repo - # if Repository.find_all_by_url(repo.url).length <= 1 - # system "rm -Rf #{self.clone_path}" - # end - # end + before_destroy :remove_unused_repos def extra_clone_url return nil unless extra_info @@ -85,6 +78,16 @@ def initialize_clone errors.add :extra_clone_url, err if err end + ## Deletes repository directory if it's inside plugin directory (i.e. belongs to plugin) + ## and this repo is not used by other repositories + def remove_unused_repos + inside_plugin_bundle = self.clone_path.include? PATH_PREFIX + nobody_else_need_it = Repository.where(url: self.url).count <= 1 + if inside_plugin_bundle && nobody_else_need_it + system "rm -Rf #{self.clone_path}" + end + end + # equality check ignoring trailing whitespace and slashes def two_remotes_equal(a,b) a.chomp.gsub(/\/$/,'') == b.chomp.gsub(/\/$/,'')