lib/imap/backup/configuration/store.rb in imap-backup-4.0.2 vs lib/imap/backup/configuration/store.rb in imap-backup-4.0.3
- old
+ new
@@ -1,6 +1,7 @@
require "json"
+require "os"
module Imap::Backup
module Configuration; end
class Configuration::Store
@@ -23,15 +24,16 @@
def path
File.dirname(pathname)
end
def save
- mkdir_private path
+ FileUtils.mkdir(path) if !File.directory?(path)
+ make_private(path) if !windows?
remove_modified_flags
remove_deleted_accounts
File.open(pathname, "w") { |f| f.write(JSON.pretty_generate(data)) }
- FileUtils.chmod 0o600, pathname
+ FileUtils.chmod(0o600, pathname) if !windows?
end
def accounts
data[:accounts]
end
@@ -52,11 +54,11 @@
def data
@data ||=
begin
if File.exist?(pathname)
- Utils.check_permissions pathname, 0o600
+ Utils.check_permissions(pathname, 0o600) if !windows?
contents = File.read(pathname)
data = JSON.parse(contents, symbolize_names: true)
else
data = {accounts: []}
end
@@ -71,11 +73,14 @@
def remove_deleted_accounts
accounts.reject! { |a| a[:delete] }
end
- def mkdir_private(path)
- FileUtils.mkdir(path) if !File.directory?(path)
+ def make_private(path)
FileUtils.chmod(0o700, path) if Utils.mode(path) != 0o700
+ end
+
+ def windows?
+ OS.windows?
end
end
end