示例#1
0
文件: Daemon.cs 项目: vmas/rsync.net
        public static int DoReceive(ClientInfo cInfo, List <FileStruct> fileList, string localName)
        {
            IOStream f        = cInfo.IoStream;
            Options  options  = cInfo.Options;
            Receiver receiver = new Receiver(options);

            options.copyLinks = false;
            f.Flush();
            if (!options.deleteAfter)
            {
                if (options.recurse && options.deleteMode && localName == null && fileList.Count > 0)
                {
                    receiver.DeleteFiles(fileList);
                }
            }
            f.IOStartBufferingOut();
            Generator gen = new Generator(options);

            gen.GenerateFiles(f, fileList, localName);
            f.Flush();
            if (fileList != null && fileList.Count != 0)
            {
                receiver.ReceiveFiles(cInfo, fileList, localName);
            }
            MainClass.Report(cInfo);
            if (options.protocolVersion >= 24)
            {
                /* send a final goodbye message */
                f.writeInt(-1);
            }
            f.Flush();
            return(0);
        }
示例#2
0
文件: Daemon.cs 项目: vmas/rsync.net
        static void DoServerSender(ClientInfo clientInfo, string[] args)
        {
            string   dir      = args[0];
            IOStream ioStream = clientInfo.IoStream;
            Options  options  = clientInfo.Options;

            if (options.verbose > 2)
            {
                Log.Write("Server sender starting");
            }
            if (options.amDaemon && config.ModuleIsWriteOnly(options.ModuleId))
            {
                MainClass.Exit("ERROR: module " + config.GetModuleName(options.ModuleId) + " is write only", clientInfo);
                return;
            }

            if (!options.relativePaths && !Util.pushDir(dir))
            {
                MainClass.Exit("Push_dir#3 " + dir + "failed", clientInfo);
                return;
            }

            FileList          fList    = new FileList(options);
            List <FileStruct> fileList = fList.sendFileList(clientInfo, args);

            if (options.verbose > 3)
            {
                Log.WriteLine("File list sent");
            }
            if (fileList.Count == 0)
            {
                MainClass.Exit("File list is empty", clientInfo);
                return;
            }
            ioStream.IOStartBufferingIn();
            ioStream.IOStartBufferingOut();

            Sender sender = new Sender(options);

            sender.SendFiles(fileList, clientInfo);
            ioStream.Flush();
            MainClass.Report(clientInfo);
            if (options.protocolVersion >= 24)
            {
                ioStream.readInt();
            }
            ioStream.Flush();
        }
示例#3
0
        public List <FileStruct> sendFileList(ClientInfo clientInfo, string[] argv)
        {
            IOStream ioStream = null;

            if (clientInfo != null)
            {
                ioStream = clientInfo.IoStream;
            }

            string dir, oldDir;
            string lastPath = String.Empty; //@todo_long seems to be Empty all the time
            string fileName = String.Empty;
            bool   useFFFD  = false;        //@todo_long seems to be false all the time

            if (showFileListProgress() && ioStream != null)
            {
                startFileListProgress("building file list");
            }
            Int64             startWrite = Options.stats.totalWritten;
            List <FileStruct> fileList   = new List <FileStruct>();

            if (ioStream != null)
            {
                ioStream.IOStartBufferingOut();
                if (Options.filesFromFD != null) //@todo_long seems to be unused because filesFromFD seems to be null all the time
                {
                    if (!string.IsNullOrEmpty(argv[0]) && !Util.pushDir(argv[0]))
                    {
                        MainClass.Exit("pushDir " + Util.fullFileName(argv[0]) + " failed", clientInfo);
                    }
                    useFFFD = true;
                }
            }
            while (true)
            {
                if (useFFFD) //@todo_long seems to be unused because useFFFD seems to be false all the time
                {
                    if ((fileName = ioStream.readFilesFromLine(Options.filesFromFD, options)).Length == 0)
                    {
                        break;
                    }
                }
                else
                {
                    if (argv.Length == 0)
                    {
                        break;
                    }
                    fileName = argv[0];
                    argv     = Util.DeleteFirstElement(argv);
                    if (fileName != null && fileName.Equals("."))
                    {
                        continue;
                    }
                    if (fileName != null)
                    {
                        fileName = fileName.Replace(@"\", "/");
                    }
                }
                // TODO: path length
                if (Directory.Exists(fileName) && !options.recurse && options.filesFrom == null)
                {
                    Log.WriteLine("skipping directory " + fileName);
                    continue;
                }

                dir    = null;
                oldDir = String.Empty;

                if (!options.relativePaths)
                {
                    int index = fileName.LastIndexOf('/');
                    if (index != -1)
                    {
                        if (index == 0)
                        {
                            dir = "/";
                        }
                        else
                        {
                            dir = fileName.Substring(0, index);
                        }
                        fileName = fileName.Substring(index + 1);
                    }
                }
                else
                {
                    if (ioStream != null && options.impliedDirs && fileName.LastIndexOf('/') > 0)
                    {
                        string fileDir = fileName.Substring(0, fileName.LastIndexOf('/'));
                        string slash   = fileName;
                        int    i       = 0;                                                            //@todo_long seems to be 0 all the time
                        while (i < fileDir.Length && i < lastPath.Length && fileDir[i] == lastPath[i]) //@todo_long seems that it is never executed because lastPath is allways Empty
                        {
                            if (fileDir[i] == '/')
                            {
                                slash = fileName.Substring(i);
                            }
                            i++;
                        }
                        if (i != fileName.LastIndexOf('/') || (i < lastPath.Length && lastPath[i] != '/'))//@todo_long seems to be executed unconditionally because i=0 and fileName.LastIndexOf('/') > 0
                        {
                            bool copyLinksSaved = options.copyLinks;
                            bool recurseSaved   = options.recurse;
                            options.copyLinks = options.copyUnsafeLinks;
                            options.recurse   = true;
                            int j;
                            while ((j = slash.IndexOf('/')) != -1)
                            {
                                sendFileName(ioStream, fileList, fileName.Substring(0, j), false, 0);
                                slash = slash.Substring(0, j) + ' ' + slash.Substring(j + 1);
                            }
                            options.copyLinks = copyLinksSaved;
                            options.recurse   = recurseSaved;
                            lastPath          = fileName.Substring(0, i);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(dir))
                {
                    oldDir = Util.currDir;
                    if (!Util.pushDir(dir))
                    {
                        Log.WriteLine("pushDir " + Util.fullFileName(dir) + " failed");
                        continue;
                    }
                    if (lastDir != null && lastDir.Equals(dir))
                    {
                        fileListDir = lastDir;
                    }
                    else
                    {
                        fileListDir = lastDir = dir;
                    }
                }
                sendFileName(ioStream, fileList, fileName, options.recurse, Options.XMIT_TOP_DIR);
                if (!string.IsNullOrEmpty(oldDir))
                {
                    fileListDir = null;
                    if (Util.popDir(oldDir))
                    {
                        MainClass.Exit("pop_dir " + Util.fullFileName(dir) + " failed", clientInfo);
                    }
                }
            }
            if (ioStream != null)
            {
                sendFileEntry(null, ioStream, 0);
                if (showFileListProgress())
                {
                    finishFileListProgress(fileList);
                }
            }
            cleanFileList(fileList, false, false);
            if (ioStream != null)
            {
                ioStream.writeInt(0);
                Options.stats.fileListSize = (int)(Options.stats.totalWritten - startWrite);
                Options.stats.numFiles     = fileList.Count;
            }

            if (options.verbose > 3)
            {
                outputFileList(fileList);
            }
            if (options.verbose > 2)
            {
                Log.WriteLine("sendFileList done");
            }
            return(fileList);
        }
示例#4
0
        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));
        }
示例#5
0
        public ArrayList sendFileList(ClientInfo cInfo, string[] argv)
        {
            IOStream f = null;

            if (cInfo != null)
            {
                f = cInfo.IoStream;
            }

            string dir = "", olddir = "";
            string lastPath = "";
            string fileName = "";
            bool   useFFFD  = false;

            if (showFileListP() && f != null)
            {
                startFileListProgress("building file list");
            }
            Int64     startWrite = Options.stats.totalWritten;
            ArrayList fileList   = new ArrayList();

            if (f != null)
            {
                f.IOStartBufferingOut();
                if (Options.filesFromFD != null)
                {
                    if (argv[0] != null && argv[0].CompareTo("") != 0 && !Util.pushDir(argv[0]))
                    {
                        MainClass.Exit("pushDir " + Util.fullFileName(argv[0]) + " failed", cInfo);
                    }
                    useFFFD = true;
                }
            }
            while (true)
            {
                if (useFFFD)
                {
                    if ((fileName = f.readFilesFromLine(Options.filesFromFD, options)).Length == 0)
                    {
                        break;
                    }
                }
                else
                {
                    if (argv.Length == 0)
                    {
                        break;
                    }
                    fileName = argv[0];
                    argv     = (string[])Util.ArrayDeleteFirstElement(argv);
                    if (fileName != null && fileName.CompareTo(".") == 0)
                    {
                        continue;
                    }
                    if (fileName != null)
                    {
                        fileName = fileName.Replace(@"\", "/");
                    }
                }
                // TODO: path length
                if (FileSystem.Directory.Exists(fileName) && !options.recurse && options.filesFrom == null)
                {
                    Log.WriteLine("skipping directory " + fileName);
                    continue;
                }

                dir    = null;
                olddir = "";

                if (options.relativePaths == 0)
                {
                    int index = fileName.LastIndexOf('/');
                    if (index != -1)
                    {
                        if (index == 0)
                        {
                            dir = "/";
                        }
                        else
                        {
                            dir = fileName.Substring(0, index);
                        }
                        fileName = fileName.Substring(index + 1);
                    }
                }
                else
                {
                    if (f != null && options.impliedDirs && fileName.LastIndexOf('/') > 0)
                    {
                        string fn    = fileName.Substring(0, fileName.LastIndexOf('/'));
                        string slash = fileName;
                        int    i     = 0;
                        while (i < fn.Length && i < lastPath.Length && fn[i] == lastPath[i])
                        {
                            if (fn[i] == '/')
                            {
                                slash = fileName.Substring(i);
                            }
                            i++;
                        }
                        if (i != fileName.LastIndexOf('/') || (i < lastPath.Length && lastPath[i] != '/'))
                        {
                            bool copyLinksSaved = options.copyLinks;
                            bool recurseSaved   = options.recurse;
                            options.copyLinks = options.copyUnsafeLinks;
                            options.recurse   = true;
                            int j;
                            while ((j = slash.IndexOf('/')) != -1)
                            {
                                sendFileName(f, fileList, fileName.Substring(0, j), false, 0);
                                slash = slash.Substring(0, j) + ' ' + slash.Substring(j + 1);
                            }
                            options.copyLinks = copyLinksSaved;
                            options.recurse   = recurseSaved;
                            lastPath          = fileName.Substring(0, i);
                        }
                    }
                }
                if (dir != null && dir != "")
                {
                    olddir = Util.currDir;
                    if (!Util.pushDir(dir))
                    {
                        Log.WriteLine("pushDir " + Util.fullFileName(dir) + " failed");
                        continue;
                    }
                    if (lastDir != null && lastDir.CompareTo(dir) == 0)
                    {
                        fileListDir = lastDir;
                    }
                    else
                    {
                        fileListDir = lastDir = dir;
                    }
                }
                sendFileName(f, fileList, fileName, options.recurse, Options.XMIT_TOP_DIR);
                if (olddir != null && olddir != "")
                {
                    fileListDir = null;
                    if (Util.popDir(olddir))
                    {
                        MainClass.Exit("pop_dir " + Util.fullFileName(dir) + " failed", cInfo);
                    }
                }
            }
            if (f != null)
            {
                sendFileEntry(null, f, 0);
                if (showFileListP())
                {
                    finishFileListProgress(fileList);
                }
            }
            cleanFileList(fileList, false, false);
            if (f != null)
            {
                f.writeInt(0);
                Options.stats.flistSize = (int)(Options.stats.totalWritten - startWrite);
                Options.stats.numFiles  = fileList.Count;
            }

            if (options.verbose > 3)
            {
                outputFileList(fileList);
            }
            if (options.verbose > 2)
            {
                Log.WriteLine("sendFileList done");
            }
            return(fileList);
        }