Create message file on startup if it doesn't exist

This commit is contained in:
Eric Budd 2018-01-30 22:27:40 -05:00
parent 475b2304ea
commit 0b4dfa6a7f
1 changed files with 18 additions and 1 deletions

19
iris.rb
View File

@ -2,7 +2,6 @@
# MVP:
# -----
# TODO: Create message file for current user if it doesn't exist
# TODO: Remove user config?
# TODO: Validate author with file owner
# TODO: Add optional title for topics
@ -97,6 +96,12 @@ class IrisFile
end
end
def self.create_message_file
raise 'File exists; refusing to overwrite!' if File.exists?(Config::MESSAGE_FILE)
File.umask(0122)
File.open(Config::MESSAGE_FILE, 'w') { |f| f.write('[]') }
end
def self.write_corpus(corpus)
File.write(Config::MESSAGE_FILE, corpus)
end
@ -483,6 +488,18 @@ class Startupper
end
def perform_startup_checks
unless File.exists?(Config::MESSAGE_FILE)
puts "You don't have a message file at #{Config::MESSAGE_FILE}."
response = Readline.readline 'Would you like me to create it for you? (y/n) ', true
if /[Yy]/ =~ response
IrisFile.create_message_file
else
puts 'Cannot run Iris without a message file!'
exit(1)
end
end
if File.stat(Config::MESSAGE_FILE).mode != 33188
puts '*' * 80
puts 'Your message file has incorrect permissions! Should be "-rw-r--r--".'