aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-02-27 21:39:28 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-02-27 21:39:28 -0300
commite00add2a401920b5c21db57b5a8b2bcd5ae427f6 (patch)
treeb8c5048bed65c12bea39d1b17a387a4f387c2ee0
parentbcd9a028016c9b29533bc894796cdb0b7ea89ab0 (diff)
downloadkeyringer-e00add2a401920b5c21db57b5a8b2bcd5ae427f6.tar.gz
keyringer-e00add2a401920b5c21db57b5a8b2bcd5ae427f6.tar.bz2
Init: setting folder structure and initial commmit
-rw-r--r--lib/backend/git.rb8
-rw-r--r--lib/backend/recipients_store.rb6
-rw-r--r--lib/keyring/recipients.rb10
-rw-r--r--lib/keyring/repository.rb42
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