From e00add2a401920b5c21db57b5a8b2bcd5ae427f6 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 27 Feb 2011 21:39:28 -0300 Subject: Init: setting folder structure and initial commmit --- lib/backend/git.rb | 8 ++++++++ lib/backend/recipients_store.rb | 6 ++++++ lib/keyring/recipients.rb | 10 +++++++--- lib/keyring/repository.rb | 42 ++++++++++++++++++++++++++--------------- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/lib/backend/git.rb b/lib/backend/git.rb index 4ce016d..3ca2d60 100644 --- a/lib/backend/git.rb +++ b/lib/backend/git.rb @@ -36,5 +36,13 @@ module Backend def clone(url, path) @git = ::Git.clone(url, path) end + + def add(pattern) + @git.add(pattern) + end + + def commit(message) + @git.commit(message) + end end end diff --git a/lib/backend/recipients_store.rb b/lib/backend/recipients_store.rb index 2dab533..bae28df 100644 --- a/lib/backend/recipients_store.rb +++ b/lib/backend/recipients_store.rb @@ -56,6 +56,12 @@ module Backend File.directory?(getPath()) end + def create() + fileName = getPath() + file = File.new(fileName, "w") + file.close + end + private def read() diff --git a/lib/keyring/recipients.rb b/lib/keyring/recipients.rb index 338c93c..f3264ed 100644 --- a/lib/keyring/recipients.rb +++ b/lib/keyring/recipients.rb @@ -20,10 +20,14 @@ module Keyring class Recipients - def initialize - path = UserConfig.instance.path - @recipientsStore = Backend::RecipientsStore.new(path) + def initialize(path = nil) + if !path + path = UserConfig.instance.path + end + # Load backend and ensure that the file exists + @recipientsStore = Backend::RecipientsStore.new(path) + @recipientsStore.create() end def addRecipient(anEmail, aKeySignature) diff --git a/lib/keyring/repository.rb b/lib/keyring/repository.rb index 88d2b54..a9e0de5 100644 --- a/lib/keyring/repository.rb +++ b/lib/keyring/repository.rb @@ -25,32 +25,44 @@ module Keyring end # Check for a valid repository - # TODO: check for repository version, .git - # and configuration. def exists?(path) - File.directory?(path) + File.directory?(path + '/.git') + end + + def getConfigPath(path) + path + '/config' end def create(path, url = nil) - keys_path = Keys.getPath(path) - - if !exists?(path) - if url - @git.clone(url, path) - else - @git.init(path) - end + keys_path = Keys.getPath(path) + config_path = getConfigPath(path) + + if url + raise "Path #{path} exists and is a git repository" if exists?(path) + @git.clone(url, path) + else + @git.init(path) end + # Setup folders + FileUtils.mkdir_p keys_path + FileUtils.mkdir_p config_path + FileUtils.chmod(0700, path) + # Reparse basedir to force absolute folder path = Pathname.new(path).realpath + + # Create recipients + recipients = Keyring::Recipients.new(path) # TODO: if needed: - # create structure - # recipients, options, version, keys + # options, version, keys # save user config - # issue initial commit - # set permissions + + @git.add('.') + + # TODO: commit just if the repository status has changed + @git.commit('Importing') end end end -- cgit v1.2.3