lib/vfs/storages/local.rb in vfs-0.3.10 vs lib/vfs/storages/local.rb in vfs-0.3.11
- old
+ new
@@ -1,12 +1,13 @@
+warn 'remove trailing spaces'
require 'tempfile'
module Vfs
module Storages
class Local
module LocalVfsHelper
- DEFAULT_BUFFER = 1024*128
+ DEFAULT_BUFFER = 1000 * 1024
attr_writer :buffer
def buffer
@buffer || DEFAULT_BUFFER
end
@@ -21,11 +22,11 @@
attrs[:dir] = stat.directory?
# attributes special for file system
attrs[:created_at] = stat.ctime
attrs[:updated_at] = stat.mtime
- attrs[:size] = stat.size
+ attrs[:size] = stat.size if stat.file?
attrs
rescue Errno::ENOENT
{}
end
@@ -43,19 +44,22 @@
block.call buff
end
end
end
- def write_file path, append, &block
- option = append ? 'a' : 'w'
+ def write_file path, append, &block
+ # TODO2 Performance lost, extra call to check file existence
+ raise "can't write, entry #{path} already exist!" if !append and ::File.exist?(path)
+
+ option = append ? 'a' : 'w'
::File.open path, option do |os|
writer = -> buff {os.write buff}
block.call writer
end
end
- def delete_file path
+ def delete_file path
::File.delete path
end
# def move_file from, to
# FileUtils.mv from, to
@@ -68,10 +72,13 @@
def create_dir path
::Dir.mkdir path
end
def delete_dir path
+ # TODO2 Performance lost, extra call to check file existence
+ raise "can't delete file (#{path})!" if ::File.file?(path)
+
FileUtils.rm_r path
end
def each_entry path, query, &block
if query
@@ -94,36 +101,23 @@
end
end
end
end
- def efficient_dir_copy from, to, override
- return false if override # FileUtils.cp_r doesn't support this behaviour
-
- from.storage.open_fs do |from_fs|
- to.storage.open_fs do |to_fs|
- if from_fs.local? and to_fs.local?
- FileUtils.cp_r from.path, to.path
- true
- else
- false
- end
- end
- end
- end
-
- # def move_dir path
- # raise 'not supported'
+ # def efficient_dir_copy from, to, override
+ # return false if override # FileUtils.cp_r doesn't support this behaviour
+ #
+ # from.storage.open_fs do |from_fs|
+ # to.storage.open_fs do |to_fs|
+ # if from_fs.local? and to_fs.local?
+ # FileUtils.cp_r from.path, to.path
+ # true
+ # else
+ # false
+ # end
+ # end
+ # end
# end
-
- # def upload_directory from_local_path, to_remote_path
- # FileUtils.cp_r from_local_path, to_remote_path
- # end
- #
- # def download_directory from_remote_path, to_local_path
- # FileUtils.cp_r from_remote_path, to_local_path
- # end
-
#
# Other
#
def local?; true end
\ No newline at end of file