class Synqa::SyncOperation
The operation of synchronising files on the remote directory with files on the local directory.
Attributes
The destination location (presumed to be remote)
The source location (presumed to be local)
Public Class Methods
# File lib/synqa.rb, line 935 def initialize(sourceLocation, destinationLocation) @sourceLocation = sourceLocation @destinationLocation = destinationLocation end
Public Instance Methods
Delete the local and remote cached content files (which will force a full recalculation of both content trees next time)
# File lib/synqa.rb, line 962 def clearCachedContentFiles @sourceLocation.clearCachedContentFile() @destinationLocation.clearCachedContentFile() end
# File lib/synqa.rb, line 1048 def closeConnections destinationLocation.closeConnections() end
Do all the copy operations, copying local directories or files which are missing from the remote location
# File lib/synqa.rb, line 989 def doAllCopyOperations(dryRun) doCopyOperations(@sourceContent, @destinationContent, dryRun) end
Do all delete operations, deleting remote directories or files which do not exist at the local location
# File lib/synqa.rb, line 994 def doAllDeleteOperations(dryRun) doDeleteOperations(@destinationContent, dryRun) end
Recursively perform all marked copy operations from the source content tree to the destination content tree, or if dryRun, just pretend to perform them.
# File lib/synqa.rb, line 1010 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.contentHost.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.contentHost.copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun) end end end
Recursively perform all marked delete operations on the destination content tree, or if dryRun, just pretend to perform them.
# File lib/synqa.rb, line 1031 def doDeleteOperations(destinationContent, dryRun) for dir in destinationContent.dirs if dir.toBeDeleted dirPath = destinationLocation.getFullPath(dir.relativePath) destinationLocation.contentHost.deleteDirectory(dirPath, dryRun) else doDeleteOperations(dir, dryRun) end end for file in destinationContent.files if file.toBeDeleted filePath = destinationLocation.getFullPath(file.relativePath) destinationLocation.contentHost.deleteFile(filePath, dryRun) end end end
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.
# File lib/synqa.rb, line 969 def doSync(options = {}) if options[:full] clearCachedContentFiles() end getContentTrees() markSyncOperations() dryRun = options[: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 closeConnections() end
Execute a (local) command, or, if dryRun, just pretend to execute it. Raise an exception if the process exit status is not 0.
# File lib/synqa.rb, line 1000 def executeCommand(command, dryRun) puts "EXECUTE: #{command}" if not dryRun system(command) checkProcessStatus(command) end end
Get the local and remote content trees
# File lib/synqa.rb, line 941 def getContentTrees @sourceContent = @sourceLocation.getContentTree() @destinationContent = @destinationLocation.getContentTree() end
On the local and remote content trees, mark the copy and delete operations required to sync the remote location to the local location.
# File lib/synqa.rb, line 948 def markSyncOperations @sourceContent.markSyncOperationsForDestination(@destinationContent) puts " ================================================ " puts "After marking for sync --" puts "" puts "Local:" @sourceContent.showIndented() puts "" puts "Remote:" @destinationContent.showIndented() end