コード例 #1
0
ファイル: FileList.cs プロジェクト: vmas/rsync.net
        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);
        }
コード例 #2
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);
        }