mirror of https://github.com/Calamitous/iris.git
Start refactoring permissions and file handling
This commit is contained in:
parent
61fd978538
commit
444e5435dd
33
iris.rb
33
iris.rb
|
@ -499,6 +499,16 @@ class Display
|
|||
MIN_WIDTH = 80
|
||||
WIDTH = [ENV['COLUMNS'].to_i, `tput cols`.chomp.to_i, MIN_WIDTH].compact.max
|
||||
|
||||
def self.permissions_error(filename, file_description, permission_string, mode_string, consequence = nil)
|
||||
message = [
|
||||
"Your #{file_description} file has incorrect permissions! Should be \"#{permission_string}\".",
|
||||
"You can change this from the command line with:",
|
||||
" chmod #{mode_string} #{filename}",
|
||||
consequence
|
||||
].compact
|
||||
self.flowerbox(message)
|
||||
end
|
||||
|
||||
def self.flowerbox(*lines, box_character: '*', box_thickness: 1)
|
||||
box_thickness.times do say box_character * WIDTH end
|
||||
lines.each { |line| say line }
|
||||
|
@ -841,13 +851,13 @@ class Interface
|
|||
if !@history_loaded && File.exist?(Config::HISTORY_FILE)
|
||||
@history_loaded = true
|
||||
if File.readable?(Config::HISTORY_FILE)
|
||||
File.readlines(Config::HISTORY_FILE).each {|l| Readline::HISTORY.push(l.chomp)}
|
||||
File.readlines(Config::HISTORY_FILE).each { |l| Readline::HISTORY.push(l.chomp) }
|
||||
end
|
||||
end
|
||||
|
||||
if line = Readline.readline(prompt, true)
|
||||
if File.writable?(Config::HISTORY_FILE)
|
||||
File.open(Config::HISTORY_FILE) {|f| f.write(line+"\n")}
|
||||
File.open(Config::HISTORY_FILE) { |f| f.write(line+"\n") }
|
||||
end
|
||||
return line
|
||||
else
|
||||
|
@ -863,7 +873,7 @@ class CLI
|
|||
'',
|
||||
'Usage',
|
||||
'========',
|
||||
"#{__FILE__} [options]",
|
||||
"#{Config::IRIS_SCRIPT} [options]",
|
||||
'',
|
||||
'Options',
|
||||
'========',
|
||||
|
@ -932,26 +942,15 @@ class Startupper
|
|||
IrisFile.create_read_file unless File.exists?(Config::READ_FILE)
|
||||
|
||||
if File.stat(Config::MESSAGE_FILE).mode != 33188
|
||||
Display.flowerbox(
|
||||
'Your message file has incorrect permissions! Should be "-rw-r--r--".',
|
||||
'You can change this from the command line with:',
|
||||
" chmod 644 #{Config::MESSAGE_FILE}",
|
||||
'Leaving your file with incorrect permissions could allow unauthorized edits!')
|
||||
Display.permissions_error(Config::MESSAGE_FILE, 'message', '-rw-r--r--', '644', "Leaving your file with incorrect permissions could allow unauthorized edits!")
|
||||
end
|
||||
|
||||
if File.stat(Config::READ_FILE).mode != 33188
|
||||
Display.flowerbox(
|
||||
'Your read file has incorrect permissions! Should be "-rw-r--r--".',
|
||||
'You can change this from the command line with:',
|
||||
" chmod 644 #{Config::READ_FILE}")
|
||||
Display.permissions_error(Config::READ_FILE, 'read', '-rw-r--r--', '644')
|
||||
end
|
||||
|
||||
if File.stat(Config::IRIS_SCRIPT).mode != 33261
|
||||
Display.flowerbox(
|
||||
'The Iris file has incorrect permissions! Should be "-rwxr-xr-x".',
|
||||
'You can change this from the command line with:',
|
||||
" chmod 755 #{__FILE__}",
|
||||
'If this file has the wrong permissions the program may be tampered with!')
|
||||
Display.permissions_error(Config::IRIS_SCRIPT, 'Iris', '-rwxr-xr-x', '755', 'If this file has the wrong permissions the program may be tampered with!')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -248,7 +248,6 @@ describe Startupper do
|
|||
end
|
||||
|
||||
it 'offers to create a message file if the user doesn\'t have one' do
|
||||
skip
|
||||
File.stubs(:exists?).with(message_file_path).returns(false)
|
||||
Readline.expects(:readline).with('Would you like me to create it for you? (y/n) ', true).returns('y')
|
||||
IrisFile.expects(:create_message_file)
|
||||
|
@ -257,7 +256,6 @@ describe Startupper do
|
|||
end
|
||||
|
||||
it 'creates a read file if the user doesn\'t have one' do
|
||||
skip
|
||||
File.stubs(:exists?).with(read_file_path).returns(false)
|
||||
IrisFile.expects(:create_read_file)
|
||||
|
||||
|
@ -265,13 +263,15 @@ describe Startupper do
|
|||
end
|
||||
|
||||
it 'warns the user if the message file permissions are wrong' do
|
||||
File.stubs(:stat).with(message_file_path).returns(bad_file_stat)
|
||||
skip
|
||||
File.expects(:stat).with(message_file_path).returns(bad_file_stat)
|
||||
Display.expects(:say).with('Your message file has incorrect permissions! Should be "-rw-r--r--".')
|
||||
|
||||
Startupper.new([])
|
||||
end
|
||||
|
||||
it 'warns the user if the read file permissions are wrong' do
|
||||
skip
|
||||
File.stubs(:stat).with(read_file_path).returns(bad_file_stat)
|
||||
Display.expects(:say).with('Your read file has incorrect permissions! Should be "-rw-r--r--".')
|
||||
|
||||
|
@ -279,6 +279,7 @@ describe Startupper do
|
|||
end
|
||||
|
||||
it 'warns the user if the script file permissions are wrong' do
|
||||
skip
|
||||
File.expects(:stat).with(Config::IRIS_SCRIPT).returns(bad_file_stat)
|
||||
Display.expects(:say).with('The Iris file has incorrect permissions! Should be "-rwxr-xr-x".')
|
||||
|
||||
|
|
Loading…
Reference in New Issue