commit 25756e74a2a30f64c3b18cb2568b646671415e69
parent 7c7dca22ff1ba9092c86b67fa25593c7c60a395a
Author: Zeger-Jan van de Weg <mail@zjvandeweg.nl>
Date: Thu, 26 Feb 2015 22:11:55 +0100
Removed BASE_DIR in favor of CONFIG_DIR and DATA_DIR
Diffstat:
5 files changed, 78 insertions(+), 22 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -17,7 +17,40 @@ end
require 'fileutils'
require 'trollop'
-require "sup"
+
+# Automagicly move all files from ~/.sup toward XDG_CONFIG_HOME and
+# XDG_DATA_HOME if set, or their default values.
+# In the future, this is to be removed, probably if you never remember
+# sup being in the ~/.sup folder
+def xdg_config_dir
+ ENV['SUP_BASE'] if ENV['SUP_BASE']
+
+ dir = ENV['XDG_CONFIG_HOME'] || File.join(ENV['HOME'], '.config/')
+ File.join(dir, 'sup')
+end
+
+def xdg_data_dir
+ ENV['SUP_BASE'] if ENV['SUP_BASE']
+
+ dir = ENV['XDG_DATA_HOME'] || File.join(ENV['HOME'], '.local/share/')
+ File.join(dir, 'sup')
+end
+
+if Dir.exist?((old_sup_dir = File.join(ENV["HOME"], ".sup"))) && !ENV['SUP_BASE']
+ FileUtils.mkdir_p xdg_config_dir
+ FileUtils.mkdir_p xdg_data_dir
+
+ FileUtils.cd old_sup_dir do
+ files = Dir.entries old_sup_dir
+ %w(config.yaml sources.yaml colors.yaml).each do |file|
+ FileUtils.mv file, xdg_config_dir if files.include? file
+ end
+
+ FileUtils.mv Dir.glob("*"), xdg_data_dir
+ end
+ FileUtils.remove_dir old_sup_dir
+end
+require 'sup'
if ENV['SUP_PROFILE']
require 'ruby-prof'
@@ -394,7 +427,7 @@ ensure
end
unless Redwood::exceptions.empty?
- File.open(File.join(BASE_DIR, "exception-log.txt"), "w") do |f|
+ File.open(File.join(DATA_DIR, "exception-log.txt"), "w") do |f|
Redwood::exceptions.each do |e, name|
f.puts "--- #{e.class.name} from thread: #{name}"
f.puts e.message, e.backtrace
@@ -404,7 +437,7 @@ unless Redwood::exceptions.empty?
----------------------------------------------------------------
We are very sorry. It seems that an error occurred in Sup. Please
accept our sincere apologies. Please submit the contents of
-#{BASE_DIR}/exception-log.txt and a brief report of the
+#{DATA_DIR}/exception-log.txt and a brief report of the
circumstances to https://github.com/sup-heliotrope/sup/issues so that
we might address this problem. Thank you!
diff --git a/bin/sup-config b/bin/sup-config
@@ -191,7 +191,7 @@ else
choose do |menu|
menu.prompt = "Store my sent mail in? "
- menu.choice('Default (an mbox in ~/.sup, aka sup://sent)') { $config[:sent_source] = 'sup://sent'} unless have_sup_sent
+ menu.choice('Default (an mbox in $XDG_DATA_DIR, default ~/.local/share/sup, aka sup://sent)') { $config[:sent_source] = 'sup://sent'} unless have_sup_sent
valid_sents = Redwood::SourceManager.sources.each do |s|
have_sup_sent = true if s.to_s.eql?('sup://sent')
diff --git a/bin/sup-dump b/bin/sup-dump
@@ -6,7 +6,12 @@ require 'xapian'
require 'trollop'
require 'set'
-BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
+if ENV["SUP_BASE"]
+ DATA_DIR = ENV['SUP_BASE']
+else
+ dir = ENV['XDG_DATA_HOME'] || File.join(ENV['HOME'], ".local/share")
+ DATA_DIR = File.join(dir, 'sup')
+end
$opts = Trollop::options do
version "sup-dump"
@@ -23,7 +28,7 @@ Usage:
EOS
end
-xapian = Xapian::Database.new File.join(BASE_DIR, 'xapian')
+xapian = Xapian::Database.new File.join(DATA_DIR, 'xapian')
version = xapian.get_metadata 'rescue-version'
version = '0' if version.empty?
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -45,20 +45,36 @@ class Module
end
module Redwood
- BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
- CONFIG_FN = File.join(BASE_DIR, "config.yaml")
- COLOR_FN = File.join(BASE_DIR, "colors.yaml")
- SOURCE_FN = File.join(BASE_DIR, "sources.yaml")
- LABEL_FN = File.join(BASE_DIR, "labels.txt")
- CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
- DRAFT_DIR = File.join(BASE_DIR, "drafts")
- SENT_FN = File.join(BASE_DIR, "sent.mbox")
- LOCK_FN = File.join(BASE_DIR, "lock")
- SUICIDE_FN = File.join(BASE_DIR, "please-kill-yourself")
- HOOK_DIR = File.join(BASE_DIR, "hooks")
- SEARCH_FN = File.join(BASE_DIR, "searches.txt")
- LOG_FN = File.join(BASE_DIR, "log")
- SYNC_OK_FN = File.join(BASE_DIR, "sync-back-ok")
+ if ENV['SUP_BASE']
+ CONFIG_DIR = ENV['SUP_BASE']
+ DATA_DIR = ENV['SUP_BASE']
+ else
+ CONFIG_DIR = if ENV['XDG_CONFIG_HOME']
+ File.join(ENV['XDG_CONFIG_DIR'], "sup")
+ else
+ File.join(ENV['HOME'], ".config/sup")
+ end
+ DATA_DIR = if ENV['XDG_DATA_HOME']
+ File.join(['XDG_DATA_HOME'], "sup")
+ else
+ File.join(ENV['HOME'], ".local/share/sup")
+ end
+ end
+
+ CONFIG_FN = File.join(CONFIG_DIR, "config.yaml")
+ COLOR_FN = File.join(CONFIG_DIR, "colors.yaml")
+ SOURCE_FN = File.join(CONFIG_DIR, "sources.yaml")
+
+ LABEL_FN = File.join(DATA_DIR, "labels.txt")
+ CONTACT_FN = File.join(DATA_DIR, "contacts.txt")
+ DRAFT_DIR = File.join(DATA_DIR, "drafts")
+ SENT_FN = File.join(DATA_DIR, "sent.mbox")
+ LOCK_FN = File.join(DATA_DIR, "lock")
+ SUICIDE_FN = File.join(DATA_DIR, "please-kill-yourself")
+ HOOK_DIR = File.join(DATA_DIR, "hooks")
+ SEARCH_FN = File.join(DATA_DIR, "searches.txt")
+ LOG_FN = File.join(DATA_DIR, "log")
+ SYNC_OK_FN = File.join(DATA_DIR, "sync-back-ok")
YAML_DOMAIN = "supmua.org"
LEGACY_YAML_DOMAIN = "masanjin.net"
@@ -162,7 +178,9 @@ module Redwood
def start bypass_sync_check = false
managers.each { |x| fail "#{x} already instantiated" if x.instantiated? }
- FileUtils.mkdir_p Redwood::BASE_DIR
+ FileUtils.mkdir_p Redwood::CONFIG_DIR
+ FileUtils.mkdir_p Redwood::DATA_DIR
+
$config = load_config Redwood::CONFIG_FN
@log_io = File.open(Redwood::LOG_FN, 'a')
Redwood::Logger.add_sink @log_io
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -57,7 +57,7 @@ EOS
include Redwood::Singleton
- def initialize dir=BASE_DIR
+ def initialize dir=DATA_DIR
@dir = dir
FileUtils.mkdir_p @dir
@lock = Lockfile.new lockfile, :retries => 0, :max_age => nil