commit cb266e510022eb35095ea6d9c1c69f79ea0a2f9b
parent 2c3010750f4823884224cff5d83ef2cba87b05a6
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Fri, 25 Sep 2015 11:18:49 +0200
Revert "Removed BASE_DIR in favor of CONFIG_DIR and DATA_DIR"
This reverts commit 25756e74a2a30f64c3b18cb2568b646671415e69.
Diffstat:
5 files changed, 22 insertions(+), 78 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -18,40 +18,7 @@ end
require 'fileutils'
require 'trollop'
-
-# 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'
+require "sup"
if ENV['SUP_PROFILE']
require 'ruby-prof'
@@ -428,7 +395,7 @@ ensure
end
unless Redwood::exceptions.empty?
- File.open(File.join(DATA_DIR, "exception-log.txt"), "w") do |f|
+ File.open(File.join(BASE_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
@@ -438,7 +405,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
-#{DATA_DIR}/exception-log.txt and a brief report of the
+#{BASE_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
@@ -177,7 +177,7 @@ else
choose do |menu|
menu.prompt = "Store my sent mail in? "
- 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
+ menu.choice('Default (an mbox in ~/.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,12 +6,7 @@ require 'xapian'
require 'trollop'
require 'set'
-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
+BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
$opts = Trollop::options do
version "sup-dump"
@@ -28,7 +23,7 @@ Usage:
EOS
end
-xapian = Xapian::Database.new File.join(DATA_DIR, 'xapian')
+xapian = Xapian::Database.new File.join(BASE_DIR, 'xapian')
version = xapian.get_metadata 'rescue-version'
version = '0' if version.empty?
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -45,36 +45,20 @@ class Module
end
module Redwood
- 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")
+ 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")
YAML_DOMAIN = "supmua.org"
LEGACY_YAML_DOMAIN = "masanjin.net"
@@ -178,9 +162,7 @@ module Redwood
def start bypass_sync_check = false
managers.each { |x| fail "#{x} already instantiated" if x.instantiated? }
- FileUtils.mkdir_p Redwood::CONFIG_DIR
- FileUtils.mkdir_p Redwood::DATA_DIR
-
+ FileUtils.mkdir_p Redwood::BASE_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=DATA_DIR
+ def initialize dir=BASE_DIR
@dir = dir
FileUtils.mkdir_p @dir
@lock = Lockfile.new lockfile, :retries => 0, :max_age => nil