1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

Use a constant for the regex and update rmdir too

This commit is contained in:
Spencer McIntyre 2018-02-05 16:06:16 -05:00
parent f441306036
commit c70bcb5869

View File

@ -21,6 +21,8 @@ class Console::CommandDispatcher::Stdapi::Fs
CHECKSUM_ALGORITHMS = %w{ md5 sha1 }
private_constant :CHECKSUM_ALGORITHMS
PATH_EXPAND_REGEX = /\%(\w*)\%/
private_constant :PATH_EXPAND_REGEX
#
# Options for the download command.
@ -246,7 +248,7 @@ class Console::CommandDispatcher::Stdapi::Fs
print_line("Usage: cd directory")
return true
end
if args[0] =~ /\%(\w*)\%/
if args[0] =~ PATH_EXPAND_REGEX
client.fs.dir.chdir(client.fs.file.expand_path(args[0].upcase))
else
client.fs.dir.chdir(args[0])
@ -309,7 +311,7 @@ class Console::CommandDispatcher::Stdapi::Fs
end
args.each do |file_path|
file_path = client.fs.file.expand_path(file_path) if file_path =~ /\%(\w*)\%/
file_path = client.fs.file.expand_path(file_path) if file_path =~ PATH_EXPAND_REGEX
client.fs.file.rm(file_path)
end
@ -327,9 +329,9 @@ class Console::CommandDispatcher::Stdapi::Fs
return true
end
old_path = args[0]
old_path = client.fs.file.expand_path(old_path) if old_path =~ /\%(\w*)\%/
old_path = client.fs.file.expand_path(old_path) if old_path =~ PATH_EXPAND_REGEX
new_path = args[1]
new_path = client.fs.file.expand_path(new_path) if new_path =~ /\%(\w*)\%/
new_path = client.fs.file.expand_path(new_path) if new_path =~ PATH_EXPAND_REGEX
client.fs.file.mv(old_path, new_path)
return true
end
@ -346,9 +348,9 @@ class Console::CommandDispatcher::Stdapi::Fs
return true
end
old_path = args[0]
old_path = client.fs.file.expand_path(old_path) if old_path =~ /\%(\w*)\%/
old_path = client.fs.file.expand_path(old_path) if old_path =~ PATH_EXPAND_REGEX
new_path = args[1]
new_path = client.fs.file.expand_path(new_path) if new_path =~ /\%(\w*)\%/
new_path = client.fs.file.expand_path(new_path) if new_path =~ PATH_EXPAND_REGEX
client.fs.file.cp(old_path, new_path)
return true
end
@ -714,9 +716,10 @@ class Console::CommandDispatcher::Stdapi::Fs
return true
end
args.each { |dir|
print_line("Removing directory: #{dir}")
client.fs.dir.rmdir(dir)
args.each { |dir_path|
dir_path = client.fs.file.expand_path(dir_path) if dir_path =~ PATH_EXPAND_REGEX
print_line("Removing directory: #{dir_path}")
client.fs.dir.rmdir(dir_path)
}
return true