Beispiel #1
0
        public void sendFileName(IOStream ioStream, List <FileStruct> fileList, string fileName, bool recursive, UInt32 baseFlags)
        {
            FileStruct file = makeFile(fileName, fileList, ioStream == null && options.deleteExcluded ? Options.SERVER_EXCLUDES : Options.ALL_EXCLUDES);

            if (file == null)
            {
                return;
            }
            EmitFileListProgress(fileList);
            if (!string.IsNullOrEmpty(file.baseName))
            {
                fileList.Add(file);
                sendFileEntry(file, ioStream, baseFlags);

                if (recursive && Util.S_ISDIR(file.mode) && (file.flags & Options.FLAG_MOUNT_POINT) == 0)
                {
                    options.localExcludeList.Clear();
                    sendDirectory(ioStream, fileList, file.GetFullName());
                }
            }
        }
Beispiel #2
0
        //private void EmitFileListProgress(List<FileStruct> fileList) //removed
        //{
        //    Log.WriteLine(" " + fileList.Count + " files...");
        //}

        //private void listFileEntry(FileStruct fileEntry)
        //{
        //    if (fileEntry.baseName == null || fileEntry.baseName.CompareTo(String.Empty) == 0)
        //    {
        //        return;
        //    }
        //    string perms = String.Empty;
        //    Log.WriteLine(perms + " " + fileEntry.length + " " + fileEntry.modTime.ToString() + " " + fileEntry.FNameTo());
        //}

        /// <summary>
        /// Write short info about files to log
        /// </summary>
        /// <param name="fileList"></param>
        private void logFileList(List <FileStruct> fileList)
        {
            for (int i = 0; i < fileList.Count; i++)
            {
                FileStruct file = fileList[i];
                if (string.IsNullOrEmpty(file.baseName))
                {
                    continue;
                }
                Log.WriteLine(" " + file.length + " " + file.modTime.ToString() + " " + file.GetFullName());
            }
        }
Beispiel #3
0
        public void sendFileEntry(FileStruct file, IOStream ioStream, UInt32 baseflags)
        {
            UInt32 flags = baseflags;
            int    l1 = 0, l2 = 0;

            if (ioStream == null)
            {
                return;
            }
            if (file == null)
            {
                ioStream.writeByte(0);
                lastName = String.Empty;
                return;
            }
            string fileName = file.GetFullName().Replace(":", String.Empty);

            for (l1 = 0;
                 lastName.Length > l1 && (fileName[l1] == lastName[l1]) && (l1 < 255);
                 l1++)
            {
            }
            l2 = fileName.Substring(l1).Length;

            flags |= Options.XMIT_SAME_NAME;

            if (l2 > 255)
            {
                flags |= Options.XMIT_LONG_NAME;
            }
            if (options.protocolVersion >= 28)
            {
                if (flags == 0 && !Util.S_ISDIR(file.mode))
                {
                    flags |= Options.XMIT_TOP_DIR;
                }

                /*if ((flags & 0xFF00) > 0 || flags == 0)
                 * {
                 *  flags |= Options.XMIT_EXTENDED_FLAGS;
                 *  f.writeByte((byte)flags);
                 *  f.writeByte((byte)(flags >> 8));
                 * }
                 * else					*/
                ioStream.writeByte((byte)flags);
            }
            else
            {
                if ((flags & 0xFF) == 0 && !Util.S_ISDIR(file.mode))
                {
                    flags |= Options.XMIT_TOP_DIR;
                }
                if ((flags & 0xFF) == 0)
                {
                    flags |= Options.XMIT_LONG_NAME;
                }
                ioStream.writeByte((byte)flags);
            }
            if ((flags & Options.XMIT_SAME_NAME) != 0)
            {
                ioStream.writeByte((byte)l1);
            }
            if ((flags & Options.XMIT_LONG_NAME) != 0)
            {
                ioStream.writeInt(l2);
            }
            else
            {
                ioStream.writeByte((byte)l2);
            }


            byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(fileName);

            ioStream.Write(b, l1, l2);
            ioStream.WriteLongInt(file.length);


            if ((flags & Options.XMIT_SAME_TIME) == 0)
            {
                ioStream.writeInt(file.modTime.Second);
            }
            if ((flags & Options.XMIT_SAME_MODE) == 0)
            {
                ioStream.writeInt((int)file.mode);
            }
            if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0)
            {
                ioStream.writeInt(file.uid);
            }
            if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0)
            {
                ioStream.writeInt(file.gid);
            }
            if (options.alwaysChecksum)
            {
                byte[] sum;
                if (!Util.S_ISDIR(file.mode))
                {
                    sum = file.sum;
                }
                else if (options.protocolVersion < 28)
                {
                    sum = new byte[16];
                }
                else
                {
                    sum = null;
                }

                if (sum != null)
                {
                    ioStream.Write(sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH);
                }
            }

            lastName = fileName;
        }
Beispiel #4
0
 public static int fileCompare(FileStruct file1, FileStruct file2)
 {
     return(uStringCompare(file1.GetFullName(), file2.GetFullName()));
 }
Beispiel #5
0
        public void SendFiles(List <FileStruct> fileList, ClientInfo clientInfo)
        {
            ShowMessage("Processing...");
            try
            {
                IOStream  ioStream = clientInfo.IoStream;
                string    fileName = String.Empty, fileName2 = String.Empty;
                SumStruct s               = null;
                int       phase           = 0;
                bool      saveMakeBackups = options.makeBackups;
                Match     match           = new Match(options);

                if (options.verbose > 2)
                {
                    Log.WriteLine("SendFiles starting");
                }
                while (true)
                {
                    fileName = String.Empty;
                    int i = ioStream.readInt();
                    if (i == -1)
                    {
                        if (phase == 0)
                        {
                            phase++;
                            checkSum.length = CheckSum.SUM_LENGTH;
                            ioStream.writeInt(-1);
                            if (options.verbose > 2)
                            {
                                Log.WriteLine("SendFiles phase=" + phase);
                            }
                            options.makeBackups = false;
                            continue;
                        }
                        break;
                    }

                    if (i < 0 || i >= fileList.Count)
                    {
                        MainClass.Exit("Invalid file index " + i + " (count=" + fileList.Count + ")", clientInfo);
                    }

                    FileStruct file = fileList[i];

                    Options.stats.currentFileIndex = i;
                    Options.stats.numTransferredFiles++;
                    Options.stats.totalTransferredSize += file.length;

                    if (!string.IsNullOrEmpty(file.baseDir))
                    {
                        fileName = file.baseDir;
                        if (!fileName.EndsWith("/"))
                        {
                            fileName += "/";
                        }
                    }
                    fileName2 = file.GetFullName();
                    fileName += file.GetFullName();
                    ShowMessage("uploading " + fileName);

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("sendFiles(" + i + ", " + fileName + ")");
                    }

                    if (options.dryRun)
                    {
                        if (!options.amServer && options.verbose != 0)
                        {
                            Log.WriteLine(fileName2);
                        }
                        ioStream.writeInt(i);
                        continue;
                    }

                    Stats initialStats = Options.stats;
                    s = ReceiveSums(clientInfo);

                    Stream fd;
                    try
                    {
                        fd = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    }
                    catch (FileNotFoundException)
                    {
                        Log.WriteLine("file has vanished: " + Util.fullFileName(fileName));
                        s = null;
                        continue;
                    }
                    catch (Exception)
                    {
                        Log.WriteLine("SendFiles failed to open " + Util.fullFileName(fileName));
                        s = null;
                        continue;
                    }

                    FStat    st = new FStat();
                    FileInfo fi = new FileInfo(fileName);
                    // TODO: path length
                    st.mTime = fi.LastWriteTime;
                    // TODO: path length
                    st.size = fi.Length;

                    MapFile mbuf = null;
                    if (st.size != 0)
                    {
                        int mapSize = (int)Math.Max(s.bLength * 3, Options.MAX_MAP_SIZE);
                        mbuf = new MapFile(fd, (int)st.size, mapSize, (int)s.bLength);
                    }

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("SendFiles mapped " + fileName + " of size " + st.size);
                    }

                    ioStream.writeInt(i);
                    Generator gen = new Generator(options);
                    gen.WriteSumHead(ioStream, s);

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("calling MatchSums " + fileName);
                    }

                    if (!options.amServer && options.verbose != 0)
                    {
                        Log.WriteLine(fileName2);
                    }

                    Token token = new Token(options);
                    token.SetCompression(fileName);

                    match.MatchSums(ioStream, s, mbuf, (int)st.size);
                    Log.LogSend(file, initialStats);

                    if (mbuf != null)
                    {
                        bool j = mbuf.UnMapFile();
                        if (j)
                        {
                            Log.WriteLine("read errors mapping " + Util.fullFileName(fileName));
                        }
                    }
                    fd.Close();

                    s.sums = null;

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("sender finished " + fileName);
                    }
                }
                options.makeBackups = saveMakeBackups;

                if (options.verbose > 2)
                {
                    Log.WriteLine("send files finished");
                }

                match.MatchReport(ioStream);
                ioStream.writeInt(-1);
            }
            finally
            {
                HideMessage();
            }
        }
Beispiel #6
0
        public void GenerateFiles(IOStream f, List <FileStruct> fileList, string localName)
        {
            int i;
            int phase = 0;


            if (options.verbose > 2)
            {
                Log.WriteLine("generator starting count=" + fileList.Count);
            }

            for (i = 0; i < fileList.Count; i++)
            {
                FileStruct file = (fileList[i]);
                if (file.baseName == null)
                {
                    continue;
                }
                if (Util.S_ISDIR(file.mode))
                {
                    continue;
                }
                ReceiveGenerator(localName != null ? localName : file.GetFullName(), file, i, f);
            }

            phase++;
            checkSum.length = CheckSum.SUM_LENGTH;
            if (options.verbose > 2)
            {
                Log.WriteLine("GenerateFiles phase=" + phase);
            }
            f.writeInt(-1);

            phase++;
            if (options.verbose > 2)
            {
                Log.WriteLine("GenerateFiles phase=" + phase);
            }

            f.writeInt(-1);

            if (options.protocolVersion >= 29 && !options.delayUpdates)
            {
                f.writeInt(-1);
            }

            /* now we need to fix any directory permissions that were
             * modified during the transfer
             * */
            for (i = 0; i < fileList.Count; i++)
            {
                FileStruct file = (fileList[i]);
                if (file.baseName != null || Util.S_ISDIR(file.mode))
                {
                    continue;
                }
                ReceiveGenerator(localName != null ? localName : file.GetFullName(), file, i, null);
            }

            if (options.verbose > 2)
            {
                Log.WriteLine("GenerateFiles finished");
            }
        }
Beispiel #7
0
        public void SendFileEntry(FileStruct file, IoStream ioStream, UInt32 baseflags)
        {
            var flags = baseflags;
            int l1 = 0, l2 = 0;

            if (ioStream == null)
            {
                return;
            }
            if (file == null)
            {
                ioStream.WriteByte(0);
                _lastName = String.Empty;
                return;
            }
            var fileName = file.GetFullName().Replace(":", String.Empty);

            for (l1 = 0;
                 _lastName.Length > l1 && (fileName[l1] == _lastName[l1]) && (l1 < 255);
                 l1++)
            {
            }
            l2 = fileName.Substring(l1).Length;

            flags |= Options.XmitSameName;

            if (l2 > 255)
            {
                flags |= Options.XmitLongName;
            }
            if (_options.ProtocolVersion >= 28)
            {
                if (flags == 0 && !Util.S_ISDIR(file.Mode))
                {
                    flags |= Options.XmitTopDir;
                }

                /*if ((flags & 0xFF00) > 0 || flags == 0)
                 * {
                 *  flags |= Options.XMIT_EXTENDED_FLAGS;
                 *  f.writeByte((byte)flags);
                 *  f.writeByte((byte)(flags >> 8));
                 * }
                 * else					*/
                ioStream.WriteByte((byte)flags);
            }
            else
            {
                if ((flags & 0xFF) == 0 && !Util.S_ISDIR(file.Mode))
                {
                    flags |= Options.XmitTopDir;
                }
                if ((flags & 0xFF) == 0)
                {
                    flags |= Options.XmitLongName;
                }
                ioStream.WriteByte((byte)flags);
            }
            if ((flags & Options.XmitSameName) != 0)
            {
                ioStream.WriteByte((byte)l1);
            }
            if ((flags & Options.XmitLongName) != 0)
            {
                ioStream.WriteInt(l2);
            }
            else
            {
                ioStream.WriteByte((byte)l2);
            }


            var b = Encoding.ASCII.GetBytes(fileName);

            ioStream.Write(b, l1, l2);
            ioStream.WriteLongInt(file.Length);


            if ((flags & Options.XmitSameTime) == 0)
            {
                ioStream.WriteInt(file.ModTime.Second);
            }
            if ((flags & Options.XmitSameMode) == 0)
            {
                ioStream.WriteInt((int)file.Mode);
            }
            if (_options.PreserveUid && (flags & Options.XmitSameUid) == 0)
            {
                ioStream.WriteInt(file.Uid);
            }
            if (_options.PreserveGid && (flags & Options.XmitSameGid) == 0)
            {
                ioStream.WriteInt(file.Gid);
            }
            if (_options.AlwaysChecksum)
            {
                byte[] sum;
                if (!Util.S_ISDIR(file.Mode))
                {
                    sum = file.Sum;
                }
                else if (_options.ProtocolVersion < 28)
                {
                    sum = new byte[16];
                }
                else
                {
                    sum = null;
                }

                if (sum != null)
                {
                    ioStream.Write(sum, 0, _options.ProtocolVersion < 21 ? 2 : CheckSum.Md4SumLength);
                }
            }

            _lastName = fileName;
        }