Class: Bdsync::Lfs

Inherits:
Core
  • Object
show all
Defined in:
lib/bdsync/lfs.rb

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

.optionsObject



10
11
12
# File 'lib/bdsync/lfs.rb', line 10

def self.options
    Core.options
end

Instance Method Details

#create_remote_file(remote_path, content) ⇒ Object

for test



94
95
96
# File 'lib/bdsync/lfs.rb', line 94

def create_remote_file remote_path, content
    File.write remote_path, content
end

#download_file(local_path, remote_path) ⇒ Object



44
45
46
47
48
49
# File 'lib/bdsync/lfs.rb', line 44

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



89
90
91
# File 'lib/bdsync/lfs.rb', line 89

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:
}

}



22
23
24
25
26
27
28
29
30
31
# File 'lib/bdsync/lfs.rb', line 22

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



81
82
83
# File 'lib/bdsync/lfs.rb', line 81

def remote_ensure_dir path
    local_ensure_dir path
end

#remote_ensure_parent(path) ⇒ Object



85
86
87
# File 'lib/bdsync/lfs.rb', line 85

def remote_ensure_parent path
    local_ensure_parent path
end

#remote_get_object(remote_path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/bdsync/lfs.rb', line 33

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



60
61
62
63
64
# File 'lib/bdsync/lfs.rb', line 60

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



71
72
73
74
# File 'lib/bdsync/lfs.rb', line 71

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



66
67
68
69
# File 'lib/bdsync/lfs.rb', line 66

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



76
77
78
79
# File 'lib/bdsync/lfs.rb', line 76

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

#upload_file(local_path, remote_path) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/bdsync/lfs.rb', line 51

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