lib/vos/drivers/ssh_vfs_storage.rb in vos-0.3.11 vs lib/vos/drivers/ssh_vfs_storage.rb in vos-0.3.12
- old
+ new
@@ -1,22 +1,32 @@
module Vos
module Drivers
- module SshVfsStorage
+ module SshVfsStorage
+ class Writer
+ def initialize out
+ @out = out
+ end
+
+ def write data
+ @out.write data
+ end
+ end
+
#
# Attributes
#
def attributes path
stat = sftp.stat! fix_path(path)
attrs = {}
attrs[:file] = stat.file?
attrs[:dir] = stat.directory?
# stat.symlink?
-
+
# attributes special for file system
attrs[:updated_at] = stat.mtime
-
+
attrs
rescue Net::SFTP::StatusException
{}
end
@@ -50,17 +60,16 @@
end
else
''
end
write_file path, false do |writer|
- writer.call data
+ writer.write data
block.call writer
end
else
- sftp.file.open fix_path(path), 'w' do |os|
- writer = -> buff {os.write buff}
- block.call writer
+ sftp.file.open fix_path(path), 'w' do |out|
+ block.call Writer.new(out)
end
end
end
def delete_file remote_file_path
@@ -83,21 +92,21 @@
exec "rm -r #{path}"
end
def each_entry path, query, &block
raise "SshVfsStorage not support :each_entry with query!" if query
-
+
sftp.dir.foreach path do |stat|
next if stat.name == '.' or stat.name == '..'
if stat.directory?
block.call stat.name, :dir
else
block.call stat.name, :file
end
end
end
-
+
# def efficient_dir_copy from, to, override
# return false if override # sftp doesn't support this behaviour
#
# from.storage.open_fs do |from_fs|
# to.storage.open_fs do |to_fs|
@@ -129,10 +138,10 @@
else
create_dir tmp_dir
tmp_dir
end
end
-
+
def local?; false end
end
end
end
\ No newline at end of file