lib/vfs/entries/dir.rb in vfs-0.3.14 vs lib/vfs/entries/dir.rb in vfs-0.3.15
- old
+ new
@@ -23,25 +23,25 @@
#
# CRUD
#
def create options = {}
- storage.open_fs do |fs|
+ storage.open do |fs|
try = 0
begin
try += 1
fs.create_dir path
rescue StandardError => error
entry = self.entry
attrs = entry.get
- if attrs[:file] #entry.exist?
+ if attrs and attrs[:file] #entry.exist?
if options[:override]
entry.destroy
else
raise Error, "entry #{self} already exist!"
end
- elsif attrs[:dir]
+ elsif attrs and attrs[:dir]
# dir already exist, no need to recreate it
return self
else
parent = self.parent
if parent.exist?
@@ -61,22 +61,22 @@
options[:override] = true
create options
end
def destroy options = {}
- storage.open_fs do |fs|
+ storage.open do |fs|
begin
fs.delete_dir path
rescue StandardError => e
attrs = get
- if attrs[:file]
+ if attrs and attrs[:file]
if options[:force]
file.destroy
else
raise Error, "can't destroy File #{dir} (You are trying to destroy it as if it's a Dir)"
end
- elsif attrs[:dir]
+ elsif attrs and attrs[:dir]
# unknown internal error
raise e
else
# do nothing, file already not exist
end
@@ -97,11 +97,11 @@
raise "invalid arguments #{args.inspect}!" if args.size > 2
options = args.last.is_a?(Hash) ? args.pop : {}
query = args.first
options[:bang] = true unless options.include? :bang
- storage.open_fs do |fs|
+ storage.open do |fs|
begin
list = []
# query option is optional and supported only for some storages (local fs for example)
fs.each_entry path, query do |name, type|
next if options[:filter] and options[:filter] != type
@@ -115,13 +115,13 @@
block ? block.call(entry) : (list << entry)
end
block ? nil : list
rescue StandardError => error
attrs = get
- if attrs[:file]
+ if attrs and attrs[:file]
raise Error, "can't query entries on File ('#{self}')!"
- elsif attrs[:dir]
+ elsif attrs and attrs[:dir]
# unknown error
raise error
else
raise Error, "'#{self}' not exist!" if options[:bang]
[]
@@ -227,27 +227,27 @@
# self.class.efficient_dir_copy(self, to, options[:override])
# rescue StandardError => error
# unknown_errors = 0
#
# attrs = get
- # if attrs[:file]
+ # if attrs and attrs[:file]
# raise Error, "can't copy File as a Dir ('#{self}')!"
- # elsif attrs[:dir]
+ # elsif attrs and attrs[:dir]
# # some unknown error (but it also maybe caused by to be fixed error in 'to')
# unknown_errors += 1
# else
# raise Error, "'#{self}' not exist!" if options[:bang]
# return true
# end
#
# attrs = to.get
- # if attrs[:file]
+ # if attrs and attrs[:file]
# if options[:override]
# to.destroy
# else
# raise Vfs::Error, "entry #{to} already exist!"
# end
- # elsif attrs[:dir]
+ # elsif attrs and attrs[:dir]
# unknown_errors += 1
# # if options[:override]
# # to.destroy
# # else
# # dir_already_exist = true
\ No newline at end of file