public int ClientRun(ClientInfo cInfo, int pid, string[] args) { Options options = cInfo.Options; IOStream f = cInfo.IoStream; FileList fList; ArrayList fileList; MainClass.SetupProtocol(cInfo); if(options.protocolVersion >= 23 && !options.readBatch) f.IOStartMultiplexIn(); if(options.amSender) { f.IOStartBufferingOut(); if (options.deleteMode && !options.deleteExcluded) { Exclude excl = new Exclude(options); excl.SendExcludeList(f); } if (options.verbose > 3) Log.Write("File list sent\n"); f.Flush(); fList = new FileList(options); fileList = fList.sendFileList(cInfo, args); if(options.verbose > 3) Log.WriteLine("file list sent"); f.Flush(); Sender sender = new Sender(options); sender.SendFiles(fileList, cInfo); f.Flush(); f.writeInt(-1); return -1; } options.dir = args[0]; if(options.dir.CompareTo("") != 0 && options.dir.IndexOf(':') == -1) { if(options.dir[0] == '/') options.dir = "c:" + options.dir; else if(options.dir.IndexOf('/') != -1) { options.dir = options.dir.Insert(options.dir.IndexOf('/') - 1,":"); } } if(!options.readBatch) { Exclude excl = new Exclude(options); excl.SendExcludeList(f); } fList = new FileList(options); fileList = fList.receiveFileList(cInfo); return Daemon.DoReceive(cInfo,fileList,null); }
public int ClientRun(ClientInfo clientInfo, int pid, string[] args) { Options options = clientInfo.Options; IOStream ioStream = clientInfo.IoStream; FileList fList; List <FileStruct> fileList; MainClass.SetupProtocol(clientInfo); if (options.protocolVersion >= 23 && !options.readBatch) { ioStream.IOStartMultiplexIn(); } if (options.amSender) { ioStream.IOStartBufferingOut(); if (options.deleteMode && !options.deleteExcluded) { Exclude excl = new Exclude(options); excl.SendExcludeList(ioStream); } if (options.verbose > 3) { Log.Write("File list sent\n"); } ioStream.Flush(); fList = new FileList(options); fileList = fList.sendFileList(clientInfo, args); if (options.verbose > 3) { Log.WriteLine("file list sent"); } ioStream.Flush(); Sender sender = new Sender(options); sender.SendFiles(fileList, clientInfo); ioStream.Flush(); ioStream.writeInt(-1); return(-1); } options.dir = args[0]; if (options.dir.CompareTo(String.Empty) != 0 && options.dir.IndexOf(':') == -1) { if (options.dir[0] == '/') { options.dir = "c:" + options.dir; } else if (options.dir.IndexOf('/') != -1) { options.dir = options.dir.Insert(options.dir.IndexOf('/') - 1, ":"); } } if (!options.readBatch) { Exclude excl = new Exclude(options); excl.SendExcludeList(ioStream); } fList = new FileList(options); fileList = fList.receiveFileList(clientInfo); return(Daemon.DoReceive(clientInfo, fileList, null)); }
/* * This function is used to check if a file should be included/excluded * from the list of files based on its name and type etc. The value of * exclude_level is set to either SERVER_EXCLUDES or ALL_EXCLUDES. */ private bool checkExcludeFile(string fileName, int isDir, int excludeLevel) { int rc; if (excludeLevel == Options.NO_EXCLUDES) return false; if (fileName.CompareTo("") != 0) { /* never exclude '.', even if somebody does --exclude '*' */ if (fileName[0] == '.' && fileName.Length == 1) return false; /* Handle the -R version of the '.' dir. */ if (fileName[0] == '/') { int len = fileName.Length; if (fileName[len-1] == '.' && fileName[len-2] == '/') return true; } } if (excludeLevel != Options.ALL_EXCLUDES) return false; Exclude excl = new Exclude(options); if (options.excludeList.Count > 0 && (rc = excl.CheckExclude(options.excludeList, fileName, isDir)) != 0) return (rc < 0) ? true : false; return false; }
public void sendDirectory(IOStream f, ArrayList fileList, string dir) { FileSystem.DirectoryInfo di = new FileSystem.DirectoryInfo(dir); if(di.Exists) { if(options.cvsExclude) { Exclude excl = new Exclude(options); excl.AddExcludeFile(ref options.localExcludeList, dir, (int)(Options.XFLG_WORD_SPLIT & Options.XFLG_WORDS_ONLY)); } FileSystem.FileInfo[] files = di.GetFiles(); for(int i=0; i< files.Length; i++) // TODO: path length sendFileName(f, fileList,files[i].FullName.Replace("\\", "/"), options.recurse,0); FileSystem.DirectoryInfo[] dirs = di.GetDirectories(); for(int i=0; i< dirs.Length; i++) // TODO: path length sendFileName(f, fileList,dirs[i].FullName.Replace("\\", "/"), options.recurse,0); } else { Log.WriteLine("Can't find directory '" + Util.fullFileName(dir) + "'"); return; } }
public static int ParseArguments(string[] args, Options options) { int argsNotUsed = 0; int i = 0; Exclude excl = new Exclude(options); while (i < args.Length) { try { switch (args[i]) { case "--version": MainClass.PrintRsyncVersion(); MainClass.Exit(String.Empty, null); break; case "--suffix": options.backupSuffix = args[++i]; break; case "--rsync-path": options.rsyncPath = args[++i]; break; case "--password-file": options.passwordFile = args[++i]; break; case "--ignore-times": case "-I": options.ignoreTimes = true; break; case "--size-only": options.sizeOnly = true; break; case "--modify-window": options.usingModifyWindow = true; options.modifyWindow = Convert.ToInt32(args[++i]); break; case "--one-file-system": case "-x": options.oneFileSystem = true; break; case "--delete": options.deleteMode = true; break; case "--existing": options.onlyExisting = true; break; case "--ignore-existing": options.optIgnoreExisting = true; break; case "--delete-after": options.deleteMode = true; options.deleteAfter = true; break; case "--delete-excluded": options.deleteMode = true; options.deleteExcluded = true; break; case "--force": options.forceDelete = true; break; case "--numeric-ids": options.numericIds = true; break; case "--exclude": excl.AddExclude(ref options.excludeList, args[++i], 0); break; case "--include": excl.AddExclude(ref options.excludeList, args[++i], (int)Options.XFLG_DEF_INCLUDE); options.forceDelete = true; break; case "--exclude-from": case "--include-from": string arg = args[i]; excl.AddExcludeFile(ref options.excludeList, args[++i], (arg.CompareTo("--exclude-from") == 0) ? 0 : (int)Options.XFLG_DEF_INCLUDE); break; case "--safe-links": options.safeSymlinks = true; break; case "--help": case "-h": MainClass.Usage(); MainClass.Exit(String.Empty, null); break; case "--backup": case "-b": options.makeBackups = true; break; case "--dry-run": case "-n": options.dryRun = true; break; case "--sparse": case "-S": options.sparseFiles = true; break; case "--cvs-exclude": case "-C": options.cvsExclude = true; break; case "--update": case "-u": options.updateOnly = true; break; case "--inplace": options.inplace = true; break; case "--keep-dirlinks": case "-K": options.keepDirLinks = true; break; case "--links": case "-l": options.preserveLinks = true; break; case "--copy-links": case "-L": options.copyLinks = true; break; case "--whole-file": case "-W": options.wholeFile = 1; break; case "--no-whole-file": options.wholeFile = 0; break; case "--copy-unsafe-links": options.copyUnsafeLinks = true; break; case "--perms": case "-p": options.preservePerms = true; break; case "--owner": case "-o": options.preserveUID = true; break; case "--group": case "-g": options.preserveGID = true; break; case "--devices": case "-D": options.preserveDevices = true; break; case "--times": case "-t": options.preserveTimes = true; break; case "--checksum": case "-c": options.alwaysChecksum = true; break; case "--verbose": case "-v": options.verbose++; break; case "--quiet": case "-q": options.quiet++; break; case "--archive": case "-a": options.archiveMode = true; break; case "--server": options.amServer = true; break; case "--sender": options.amSender = true; break; case "--recursive": case "-r": options.recurse = true; break; case "--relative": case "-R": options.relativePaths = true; break; case "--no-relative": options.relativePaths = false; break; case "--rsh": case "-e": options.shellCmd = args[++i]; break; case "--block-size": case "-B": options.blockSize = Convert.ToInt32(args[++i]); break; case "--max-delete": options.maxDelete = Convert.ToInt32(args[++i]); break; case "--timeout": options.ioTimeout = Convert.ToInt32(args[++i]); break; case "--temp-dir": case "-T": options.tmpDir = args[++i]; break; case "--compare-dest": options.compareDest = args[++i]; break; case "--link-dest": options.compareDest = args[++i]; break; case "--compress": case "-z": options.doCompression = true; break; case "--stats": options.doStats = true; break; case "--progress": options.doProgress = true; break; case "--partial": options.keepPartial = true; break; case "--partial-dir": options.partialDir = args[++i]; break; case "--ignore-errors": options.ignoreErrors = true; break; case "--blocking-io": options.blockingIO = 1; break; case "--no-blocking-io": options.blockingIO = 0; break; case "-P": options.doProgress = true; options.keepPartial = true; break; case "--log-format": options.logFormat = args[++i]; break; case "--bwlimit": options.bwLimit = Convert.ToInt32(args[++i]); break; case "--backup-dir": options.backupDir = args[++i]; break; case "--hard-links": case "-H": options.preserveHardLinks = true; break; case "--read-batch": options.batchName = args[++i]; options.readBatch = true; break; case "--write-batch": options.batchName = args[++i]; options.writeBatch = true; break; case "--files-from": options.filesFrom = args[++i]; break; case "--from0": options.eolNulls = true; break; case "--no-implied-dirs": options.impliedDirs = true; break; case "--protocol": options.protocolVersion = Convert.ToInt32(args[++i]); break; case "--checksum-seed": options.checksumSeed = Convert.ToInt32(args[++i]); break; case "--daemon": options.amDaemon = true; break; case "--address": options.bindAddress = args[++i]; break; case "--port": options.rsyncPort = Convert.ToInt32(args[++i]); break; case "--config": options.configFile = args[++i].Trim(); break; default: { argsNotUsed += ParseMergeArgs(args[i], options); break; } } i++; } catch { return -1; } } if (options.amSender && !options.amServer) { MainClass.Usage(); MainClass.Exit(String.Empty, null); } if (options.ioTimeout > 0 && options.ioTimeout < options.selectTimeout) { options.selectTimeout = options.ioTimeout; } return argsNotUsed; }
public static int ParseArguments(string[] args, Options options) { int argsNotUsed = 0; int i = 0; Exclude excl = new Exclude(options); while (i < args.Length) { try { switch (args[i]) { case "--version": MainClass.PrintRsyncVersion(); MainClass.Exit("", null); break; case "--suffix": options.backupSuffix = args[++i]; break; case "--rsync-path": options.rsyncPath = args[++i]; break; case "--password-file": options.passwordFile = args[++i]; break; case "--ignore-times": case "-I": options.ignoreTimes = true; break; case "--size-only": options.sizeOnly = true; break; case "--modify-window": options.usingModifyWindow = true; options.modifyWindow = Convert.ToInt32(args[++i]); break; case "--one-file-system": case "-x": options.oneFileSystem = true; break; case "--delete": options.deleteMode = true; break; case "--existing": options.onlyExisting = true; break; case "--ignore-existing": options.optIgnoreExisting = true; break; case "--delete-after": options.deleteMode = true; options.deleteAfter = true; break; case "--delete-excluded": options.deleteMode = true; options.deleteExcluded = true; break; case "--force": options.forceDelete = true; break; case "--numeric-ids": options.numericIds = true; break; case "--exclude": excl.AddExclude(ref options.excludeList, args[++i], 0); break; case "--include": excl.AddExclude(ref options.excludeList, args[++i], (int)Options.XFLG_DEF_INCLUDE); options.forceDelete = true; break; case "--exclude-from": case "--include-from": string arg = args[i]; excl.AddExcludeFile(ref options.excludeList, args[++i], (arg.CompareTo("--exclude-from") == 0) ? 0 :(int)Options.XFLG_DEF_INCLUDE); break; case "--safe-links": options.safeSymlinks = true; break; case "--help": case "-h": MainClass.Usage(); MainClass.Exit("", null); break; case "--backup": case "-b": options.makeBackups = true; break; case "--dry-run": case "-n": options.dryRun = true; break; case "--sparse": case "-S": options.sparseFiles = true; break; case "--cvs-exclude": case "-C": options.cvsExclude = true; break; case "--update": case "-u": options.updateOnly = true; break; case "--inplace": options.inplace = true; break; case "--keep-dirlinks": case "-K": options.keepDirLinks = true; break; case "--links": case "-l": options.preserveLinks = true; break; case "--copy-links": case "-L": options.copyLinks = true; break; case "--whole-file": case "-W": options.wholeFile = 1; break; case "--no-whole-file": options.wholeFile = 0; break; case "--copy-unsafe-links": options.copyUnsafeLinks = true; break; case "--perms": case "-p": options.preservePerms = true; break; case "--owner": case "-o": options.preserveUID = true; break; case "--group": case "-g": options.preserveGID = true; break; case "--devices": case "-D": options.preserveDevices = true; break; case "--times": case "-t": options.preserveTimes = true; break; case "--checksum": case "-c": options.alwaysChecksum = true; break; case "--verbose": case "-v": options.verbose++; break; case "--quiet": case "-q": options.quiet++; break; case "--archive": case "-a": options.archiveMode = true; break; case "--server": options.amServer = true; break; case "--sender": options.amSender = true; break; case "--recursive": case "-r": options.recurse = true; break; case "--relative": case "-R": options.relativePaths = 1; break; case "--no-relative": options.relativePaths = 0; break; case "--rsh": case "-e": options.shellCmd = args[++i]; break; case "--block-size": case "-B": options.blockSize = Convert.ToInt32(args[++i]); break; case "--max-delete": options.maxDelete = Convert.ToInt32(args[++i]); break; case "--timeout": options.ioTimeout = Convert.ToInt32(args[++i]); break; case "--temp-dir": case "-T": options.tmpDir = args[++i]; break; case "--compare-dest": options.compareDest = args[++i]; break; case "--link-dest": options.compareDest = args[++i]; break; case "--compress": case "-z": options.doCompression = true; break; case "--stats": options.doStats = true; break; case "--progress": options.doProgress = true; break; case "--partial": options.keepPartial = true; break; case "--partial-dir": options.partialDir = args[++i]; break; case "--ignore-errors": options.ignoreErrors = true; break; case "--blocking-io": options.blockingIO = 1; break; case "--no-blocking-io": options.blockingIO = 0; break; case "-P": options.doProgress = true; options.keepPartial = true; break; case "--log-format": options.logFormat = args[++i]; break; case "--bwlimit": options.bwLimit = Convert.ToInt32(args[++i]); break; case "--backup-dir": options.backupDir = args[++i]; break; case "--hard-links": case "-H": options.preserveHardLinks = true; break; case "--read-batch": options.batchName = args[++i]; options.readBatch = true; break; case "--write-batch": options.batchName = args[++i]; options.writeBatch = true; break; case "--files-from": options.filesFrom = args[++i]; break; case "--from0": options.eolNulls = true; break; case "--no-implied-dirs": options.impliedDirs = true; break; case "--protocol": options.protocolVersion = Convert.ToInt32(args[++i]); break; case "--checksum-seed": options.checksumSeed = Convert.ToInt32(args[++i]); break; case "--daemon": options.amDaemon = true; break; case "--address": options.bindAddress = args[++i]; break; case "--port": options.rsyncPort = Convert.ToInt32(args[++i]); break; case "--config": options.configFile = args[++i].Trim(); break; default: { argsNotUsed += ParseMergeArgs(args[i], options); break; } } i++; } catch { return(-1); } } if (options.amSender && !options.amServer) { MainClass.Usage(); MainClass.Exit("", null); } if (options.ioTimeout > 0 && options.ioTimeout < options.selectTimeout) { options.selectTimeout = options.ioTimeout; } return(argsNotUsed); }
public static void DoServerReceive(ClientInfo cInfo, string[] args) { Options options = cInfo.Options; IOStream f = cInfo.IoStream; if (options.verbose > 2) { Log.Write("Server receive starting"); } if (options.amDaemon && config.ModuleIsReadOnly(options.ModuleId)) { MainClass.Exit("ERROR: module " + config.GetModuleName(options.ModuleId) + " is read only", cInfo); return; } f.IOStartBufferingIn(); if (options.deleteMode && !options.deleteExcluded) { Exclude excl = new Exclude(options); excl.ReceiveExcludeList(f); } FileList fList = new FileList(cInfo.Options); List<FileStruct> fileList = fList.receiveFileList(cInfo); DoReceive(cInfo, fileList, null); }
public static void StartServer(ClientInfo cInfo, string[] args) { IOStream f = cInfo.IoStream; Options options = cInfo.Options; if (options.protocolVersion >= 23) { f.IOStartMultiplexOut(); } if (options.amSender) { options.keepDirLinks = false; /* Must be disabled on the sender. */ Exclude excl = new Exclude(options); excl.ReceiveExcludeList(f); DoServerSender(cInfo, args); } else { DoServerReceive(cInfo, args); } }
public static int ParseArguments(string[] args, Options options) { var argsNotUsed = 0; var i = 0; var excl = new Exclude(options); while (i < args.Length) { try { switch (args[i]) { case "--suffix": options.BackupSuffix = args[++i]; break; case "--rsync-path": options.RsyncPath = args[++i]; break; case "--password-file": options.PasswordFile = args[++i]; break; case "--ignore-times": case "-I": options.IgnoreTimes = true; break; case "--size-only": options.SizeOnly = true; break; case "--modify-window": options.UsingModifyWindow = true; options.ModifyWindow = Convert.ToInt32(args[++i]); break; case "--one-file-system": case "-x": options.OneFileSystem = true; break; case "--delete": options.DeleteMode = true; break; case "--existing": options.OnlyExisting = true; break; case "--ignore-existing": options.OptIgnoreExisting = true; break; case "--delete-after": options.DeleteMode = true; options.DeleteAfter = true; break; case "--delete-excluded": options.DeleteMode = true; options.DeleteExcluded = true; break; case "--force": options.ForceDelete = true; break; case "--numeric-ids": options.NumericIds = true; break; case "--exclude": excl.AddExclude(ref options.ExcludeList, args[++i], 0); break; case "--include": excl.AddExclude(ref options.ExcludeList, args[++i], (int)Options.XflgDefInclude); options.ForceDelete = true; break; case "--exclude-from": case "--include-from": var arg = args[i]; excl.AddExcludeFile(ref options.ExcludeList, args[++i], (arg.CompareTo("--exclude-from") == 0) ? 0 : (int)Options.XflgDefInclude); break; case "--safe-links": options.SafeSymlinks = true; break; case "--help": case "-h": WinRsync.Exit(String.Empty, null); break; case "--backup": case "-b": options.MakeBackups = true; break; case "--dry-run": case "-n": options.DryRun = true; break; case "--sparse": case "-S": options.SparseFiles = true; break; case "--cvs-exclude": case "-C": options.CvsExclude = true; break; case "--update": case "-u": options.UpdateOnly = true; break; case "--inplace": options.Inplace = true; break; case "--keep-dirlinks": case "-K": options.KeepDirLinks = true; break; case "--links": case "-l": options.PreserveLinks = true; break; case "--copy-links": case "-L": options.CopyLinks = true; break; case "--whole-file": case "-W": options.WholeFile = 1; break; case "--no-whole-file": options.WholeFile = 0; break; case "--copy-unsafe-links": options.CopyUnsafeLinks = true; break; case "--perms": case "-p": options.PreservePerms = true; break; case "--owner": case "-o": options.PreserveUid = true; break; case "--group": case "-g": options.PreserveGid = true; break; case "--devices": case "-D": options.PreserveDevices = true; break; case "--times": case "-t": options.PreserveTimes = true; break; case "--checksum": case "-c": options.AlwaysChecksum = true; break; case "--verbose": case "-v": options.Verbose++; break; case "--quiet": case "-q": options.Quiet++; break; case "--archive": case "-a": options.ArchiveMode = true; break; case "--server": options.AmServer = true; break; case "--sender": options.AmSender = true; break; case "--recursive": case "-r": options.Recurse = true; break; case "--relative": case "-R": options.RelativePaths = true; break; case "--no-relative": options.RelativePaths = false; break; case "--rsh": case "-e": options.ShellCmd = args[++i]; break; case "--block-size": case "-B": options.BlockSize = Convert.ToInt32(args[++i]); break; case "--max-delete": options.MaxDelete = Convert.ToInt32(args[++i]); break; case "--timeout": options.IoTimeout = Convert.ToInt32(args[++i]); break; case "--temp-dir": case "-T": options.TmpDir = args[++i]; break; case "--compare-dest": options.CompareDest = args[++i]; break; case "--link-dest": options.CompareDest = args[++i]; break; case "--compress": case "-z": options.DoCompression = true; break; case "--stats": options.DoStats = true; break; case "--progress": options.DoProgress = true; break; case "--partial": options.KeepPartial = true; break; case "--partial-dir": options.PartialDir = args[++i]; break; case "--ignore-errors": options.IgnoreErrors = true; break; case "--blocking-io": options.BlockingIo = 1; break; case "--no-blocking-io": options.BlockingIo = 0; break; case "-P": options.DoProgress = true; options.KeepPartial = true; break; case "--log-format": options.LogFormat = args[++i]; break; case "--bwlimit": options.BwLimit = Convert.ToInt32(args[++i]); break; case "--backup-dir": options.BackupDir = args[++i]; break; case "--hard-links": case "-H": options.PreserveHardLinks = true; break; case "--read-batch": options.BatchName = args[++i]; options.ReadBatch = true; break; case "--write-batch": options.BatchName = args[++i]; options.WriteBatch = true; break; case "--files-from": options.FilesFrom = args[++i]; break; case "--from0": options.EolNulls = true; break; case "--no-implied-dirs": options.ImpliedDirs = true; break; case "--protocol": options.ProtocolVersion = Convert.ToInt32(args[++i]); break; case "--checksum-seed": options.ChecksumSeed = Convert.ToInt32(args[++i]); break; case "--daemon": options.AmDaemon = true; break; case "--address": options.BindAddress = args[++i]; break; case "--port": options.RsyncPort = Convert.ToInt32(args[++i]); break; case "--config": options.ConfigFile = args[++i].Trim(); break; default: { argsNotUsed += ParseMergeArgs(args[i], options); break; } } i++; } catch { return(-1); } } if (options.AmSender && !options.AmServer) { WinRsync.Exit(String.Empty, null); } if (options.IoTimeout > 0 && options.IoTimeout < options.SelectTimeout) { options.SelectTimeout = options.IoTimeout; } return(argsNotUsed); }