From c27fcbec9f785494c4810334fe8e120534f03f46 Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Sat, 31 Dec 2016 15:34:59 +0100 Subject: [PATCH 1/3] Add deletion of repos, taken from pull request #19 --- app/models/repository/git_remote.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/models/repository/git_remote.rb b/app/models/repository/git_remote.rb index f5c0b2d..c0fae74 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.relative_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(/\/$/,'') From 56e29f4c8e3369ab136ab7c3d4390a5cae5a24fb Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Sat, 31 Dec 2016 15:45:55 +0100 Subject: [PATCH 2/3] Remove unnecessary todo, clean up todos --- DEVNOTES.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 From e8dc72f7f5733502bb4f196a245b77fa9477985c Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Sat, 31 Dec 2016 16:09:56 +0100 Subject: [PATCH 3/3] Fix issue with url --- app/models/repository/git_remote.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository/git_remote.rb b/app/models/repository/git_remote.rb index c0fae74..35173a6 100644 --- a/app/models/repository/git_remote.rb +++ b/app/models/repository/git_remote.rb @@ -82,7 +82,7 @@ def initialize_clone ## 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.relative_url).count <= 1 + 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