Class: Bdsync::Lfs
Instance Attribute Summary
Attributes inherited from Core
#data_path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Core
#do_first_time_sync_from_local, #do_first_time_sync_from_remote, #do_sync_from_local, #do_sync_from_remote, #handle_local_conflict, #handle_local_entry, #handle_remote_conflict, #handle_remote_entry, #is_same_contents, #load_data, #local_ensure_dir, #local_ensure_parent, #local_mkdir, #local_remove_directory, #local_remove_file, #local_rename, #save_data, #synchronize, #traverse_local_path, #traverse_remote_path, #update_directory_data, #update_file_data
Constructor Details
#initialize(params) ⇒ Lfs
Returns a new instance of Lfs.
6
7
8
|
# File 'lib/bdsync/lfs.rb', line 6
def initialize params
super params, "lfs"
end
|
Class Method Details
.options ⇒ Object
10
11
12
|
# File 'lib/bdsync/lfs.rb', line 10
def self.options
Core.options
end
|
Instance Method Details
#download_file(local_path, remote_path) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/bdsync/lfs.rb', line 48
def download_file local_path, remote_path
local_ensure_parent local_path
puts "#{Utils.caller_info 1} cp #{remote_path}, #{local_path}".white
FileUtils.cp remote_path, local_path
end
|
#get_remote_file_md5(path) ⇒ Object
93
94
95
|
# File 'lib/bdsync/lfs.rb', line 93
def get_remote_file_md5 path
Utils.file_md5 path
end
|
#remote_dir_foreach(remote_path) ⇒ Object
yield object like this {
name:
attributes: {
directory?:
mtime:
}
}
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/bdsync/lfs.rb', line 26
def remote_dir_foreach remote_path
Dir.foreach(remote_path) { |filename|
file_path = "#{remote_path}/#{filename}"
yield OpenStruct.new name: filename, attributes: OpenStruct.new(
directory?: File.directory?(file_path),
mtime: File.mtime(file_path).to_i
)
}
end
|
#remote_ensure_dir(path) ⇒ Object
85
86
87
|
# File 'lib/bdsync/lfs.rb', line 85
def remote_ensure_dir path
local_ensure_dir path
end
|
#remote_ensure_parent(path) ⇒ Object
89
90
91
|
# File 'lib/bdsync/lfs.rb', line 89
def remote_ensure_parent path
local_ensure_parent path
end
|
#remote_get_object(remote_path) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/bdsync/lfs.rb', line 37
def remote_get_object remote_path
stat = File.lstat remote_path
OpenStruct.new(
directory?: stat.directory?,
mtime: stat.mtime.to_i
)
rescue Errno::ENOENT
nil
end
|
#remote_mkdir(remote_path) ⇒ Object
64
65
66
67
68
|
# File 'lib/bdsync/lfs.rb', line 64
def remote_mkdir remote_path
puts "#{Utils.caller_info 1} mkdir #{remote_path}".white
FileUtils.mkdir remote_path
remote_get_object remote_path
end
|
#remote_remove_dir(remote_path) ⇒ Object
75
76
77
78
|
# File 'lib/bdsync/lfs.rb', line 75
def remote_remove_dir remote_path
puts "#{Utils.caller_info 1} rm_rf #{remote_path}".white
FileUtils.rm_rf remote_path
end
|
#remote_remove_file(remote_path) ⇒ Object
70
71
72
73
|
# File 'lib/bdsync/lfs.rb', line 70
def remote_remove_file remote_path
puts "#{Utils.caller_info 1} rm #{remote_path}".white
FileUtils.rm remote_path
end
|
#remote_rename(remote_path, new_remote_path) ⇒ Object
80
81
82
83
|
# File 'lib/bdsync/lfs.rb', line 80
def remote_rename remote_path, new_remote_path
puts "#{Utils.caller_info 1} mv #{remote_path} #{new_remote_path}".yellow
FileUtils.mv remote_path, new_remote_path
end
|
#start_session(&block) ⇒ Object
14
15
16
|
# File 'lib/bdsync/lfs.rb', line 14
def start_session &block
yield
end
|
#upload_file(local_path, remote_path) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/bdsync/lfs.rb', line 55
def upload_file local_path, remote_path
remote_ensure_parent remote_path
puts "#{Utils.caller_info 1} cp #{local_path}, #{remote_path}".white
FileUtils.cp local_path, remote_path
remote_get_object remote_path
end
|