Class: Synqa::SyncOperation
- Inherits:
-
Object
- Object
- Synqa::SyncOperation
- Defined in:
- lib/synqa.rb
Overview
The operation of synchronising files on the remote directory with files on the local directory.
Instance Attribute Summary collapse
-
#destinationLocation ⇒ Object
readonly
The destination location (presumed to be remote).
-
#sourceLocation ⇒ Object
readonly
The source location (presumed to be local).
Instance Method Summary collapse
-
#clearCachedContentFiles ⇒ Object
Delete the local and remote cached content files (which will force a full recalculation of both content trees next time).
-
#doAllCopyOperations(dryRun) ⇒ Object
Do all the copy operations, copying local directories or files which are missing from the remote location.
-
#doAllDeleteOperations(dryRun) ⇒ Object
Do all delete operations, deleting remote directories or files which do not exist at the local location.
-
#doCopyOperations(sourceContent, destinationContent, dryRun) ⇒ Object
Recursively perform all marked copy operations from the source content tree to the destination content tree, or if dryRun, just pretend to perform them.
-
#doDeleteOperations(destinationContent, dryRun) ⇒ Object
Recursively perform all marked delete operations on the destination content tree, or if dryRun, just pretend to perform them.
-
#doSync(options = {}) ⇒ Object
Do the sync.
-
#executeCommand(command, dryRun) ⇒ Object
Execute a (local) command, or, if dryRun, just pretend to execute it.
-
#getContentTrees ⇒ Object
Get the local and remote content trees.
-
#initialize(sourceLocation, destinationLocation) ⇒ SyncOperation
constructor
A new instance of SyncOperation.
-
#markSyncOperations ⇒ Object
On the local and remote content trees, mark the copy and delete operations required to sync the remote location to the local location.
Constructor Details
#initialize(sourceLocation, destinationLocation) ⇒ SyncOperation
Returns a new instance of SyncOperation.
893 894 895 896 |
# File 'lib/synqa.rb', line 893 def initialize(sourceLocation, destinationLocation) @sourceLocation = sourceLocation @destinationLocation = destinationLocation end |
Instance Attribute Details
#destinationLocation ⇒ Object (readonly)
The destination location (presumed to be remote)
891 892 893 |
# File 'lib/synqa.rb', line 891 def destinationLocation @destinationLocation end |
#sourceLocation ⇒ Object (readonly)
The source location (presumed to be local)
888 889 890 |
# File 'lib/synqa.rb', line 888 def sourceLocation @sourceLocation end |
Instance Method Details
#clearCachedContentFiles ⇒ Object
Delete the local and remote cached content files (which will force a full recalculation of both content trees next time)
920 921 922 923 |
# File 'lib/synqa.rb', line 920 def clearCachedContentFiles @sourceLocation.clearCachedContentFile() @destinationLocation.clearCachedContentFile() end |
#doAllCopyOperations(dryRun) ⇒ Object
Do all the copy operations, copying local directories or files which are missing from the remote location
946 947 948 |
# File 'lib/synqa.rb', line 946 def doAllCopyOperations(dryRun) doCopyOperations(@sourceContent, @destinationContent, dryRun) end |
#doAllDeleteOperations(dryRun) ⇒ Object
Do all delete operations, deleting remote directories or files which do not exist at the local location
951 952 953 |
# File 'lib/synqa.rb', line 951 def doAllDeleteOperations(dryRun) doDeleteOperations(@destinationContent, dryRun) end |
#doCopyOperations(sourceContent, destinationContent, dryRun) ⇒ Object
Recursively perform all marked copy operations from the source content tree to the destination content tree, or if dryRun, just pretend to perform them.
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'lib/synqa.rb', line 967 def doCopyOperations(sourceContent, destinationContent, dryRun) for dir in sourceContent.dirs if dir.copyDestination != nil sourcePath = sourceLocation.getFullPath(dir.relativePath) destinationPath = destinationLocation.getFullPath(dir.copyDestination.relativePath) destinationLocation.userAtHost.copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun) else doCopyOperations(dir, destinationContent.getDir(dir.name), dryRun) end end for file in sourceContent.files if file.copyDestination != nil sourcePath = sourceLocation.getFullPath(file.relativePath) destinationPath = destinationLocation.getFullPath(file.copyDestination.relativePath) destinationLocation.userAtHost.copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun) end end end |
#doDeleteOperations(destinationContent, dryRun) ⇒ Object
Recursively perform all marked delete operations on the destination content tree, or if dryRun, just pretend to perform them.
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
# File 'lib/synqa.rb', line 988 def doDeleteOperations(destinationContent, dryRun) for dir in destinationContent.dirs if dir.toBeDeleted dirPath = destinationLocation.getFullPath(dir.relativePath) destinationLocation.userAtHost.deleteDirectory(dirPath, dryRun) else doDeleteOperations(dir, dryRun) end end for file in destinationContent.files if file.toBeDeleted filePath = destinationLocation.getFullPath(file.relativePath) destinationLocation.userAtHost.deleteFile(filePath, dryRun) end end end |
#doSync(options = {}) ⇒ Object
Do the sync. Options: :full = true means clear the cached content files first, :dryRun means don’t do the actual copies and deletes, but just show what they would be.
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'lib/synqa.rb', line 927 def doSync( = {}) if [:full] clearCachedContentFiles() end getContentTrees() markSyncOperations() dryRun = [:dryRun] if not dryRun @destinationLocation.clearCachedContentFile() end doAllCopyOperations(dryRun) doAllDeleteOperations(dryRun) if (not dryRun and @destinationLocation.cachedContentFile and @sourceLocation.cachedContentFile and File.exists?(@sourceLocation.cachedContentFile)) FileUtils::Verbose.cp(@sourceLocation.cachedContentFile, @destinationLocation.cachedContentFile) end end |
#executeCommand(command, dryRun) ⇒ Object
Execute a (local) command, or, if dryRun, just pretend to execute it. Raise an exception if the process exit status is not 0.
957 958 959 960 961 962 963 |
# File 'lib/synqa.rb', line 957 def executeCommand(command, dryRun) puts "EXECUTE: #{command}" if not dryRun system(command) checkProcessStatus(command) end end |
#getContentTrees ⇒ Object
Get the local and remote content trees
899 900 901 902 |
# File 'lib/synqa.rb', line 899 def getContentTrees @sourceContent = @sourceLocation.getContentTree() @destinationContent = @destinationLocation.getContentTree() end |
#markSyncOperations ⇒ Object
On the local and remote content trees, mark the copy and delete operations required to sync the remote location to the local location.
906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/synqa.rb', line 906 def markSyncOperations @sourceContent.markSyncOperationsForDestination(@destinationContent) puts " ================================================ " puts "After marking for sync --" puts "" puts "Local:" @sourceContent.showIndented() puts "" puts "Remote:" @destinationContent.showIndented() end |