public void WriteSumHead(IOStream f, SumStruct sum) { if(sum == null) sum = new SumStruct(); f.writeInt(sum.count); f.writeInt((int)sum.bLength); if (options.protocolVersion >= 27) f.writeInt(sum.s2Length); f.writeInt((int)sum.remainder); }
public void WriteSumHead(IOStream f, SumStruct sum) { if (sum == null) { sum = new SumStruct(); } f.writeInt(sum.count); f.writeInt((int)sum.bLength); if (options.protocolVersion >= 27) { f.writeInt(sum.s2Length); } f.writeInt((int)sum.remainder); }
public void GenerateFiles(IOStream f, ArrayList 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 = ((FileStruct)fileList[i]); if (file.baseName == null) continue; if(Util.S_ISDIR(file.mode)) continue; ReceiveGenerator(localName != null ? localName : file.FNameTo() ,file, i, f); } phase++; checkSum.cSumLength = 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 = ((FileStruct)fileList[i]); if (file.baseName != null || Util.S_ISDIR(file.mode)) continue; ReceiveGenerator(localName != null ? localName : file.FNameTo() ,file, i, null); } if (options.verbose > 2) Log.WriteLine("GenerateFiles finished"); }
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); }
public void SimpleSendToken(IOStream f, int token, MapFile buf, int offset, int n) { if (n > 0) { int l = 0; while (l < n) { int n1 = Math.Min(Match.CHUNK_SIZE, n - l); f.writeInt(n1); int off = buf.MapPtr(offset + l, n1); f.Write(buf.p, off, n1); l += n1; } } if (token != -2) { f.writeInt(-(token + 1)); } }
/// <summary> /// /// </summary> /// <param name="cInfo"></param> public static void SetupProtocol(ClientInfo cInfo) { IOStream f = cInfo.IoStream; Options options = cInfo.Options; if (options.remoteProtocol == 0) { if (!options.readBatch) { f.writeInt(options.protocolVersion); } options.remoteProtocol = f.readInt(); if (options.protocolVersion > options.remoteProtocol) { options.protocolVersion = options.remoteProtocol; } } if (options.readBatch && options.remoteProtocol > options.protocolVersion) { MainClass.Exit("The protocol version in the batch file is too new", null); } if (options.verbose > 3) { Log.WriteLine("(" + (options.amServer ? "Server" : "Client") + ") Protocol versions: remote=" + options.remoteProtocol + ", negotiated=" + options.protocolVersion); } if (options.remoteProtocol < Options.MIN_PROTOCOL_VERSION || options.remoteProtocol > Options.MAX_PROTOCOL_VERSION) { MainClass.Exit("Protocol version mistmatch", null); } if (options.amServer) { if (options.checksumSeed == 0) { options.checksumSeed = (int)System.DateTime.Now.Ticks; } f.writeInt(options.checksumSeed); } else { options.checksumSeed = f.readInt(); } }
public void SendExcludeList(IOStream f) { if (options.listOnly && !options.recurse) { AddExclude(ref options.excludeList, "/*/*", 0); } foreach (ExcludeStruct ent in options.excludeList) { int l; string p; if (ent.pattern.Length == 0 || ent.pattern.Length > Options.MAXPATHLEN) { continue; } l = ent.pattern.Length; p = ent.pattern; if ((ent.matchFlags & Options.MATCHFLG_DIRECTORY) != 0) { p += "/\0"; } if ((ent.matchFlags & Options.MATCHFLG_INCLUDE) != 0) { f.writeInt(l + 2); f.IOPrintf("+ "); } else if ((p[0] == '-' || p[0] == '+') && p[1] == ' ') { f.writeInt(l + 2); f.IOPrintf("- "); } else { f.writeInt(l); } f.IOPrintf(p); } f.writeInt(0); }
public void GenerateAndSendSums(Stream fd, long len, IOStream f, Stream fCopy) { long i; MapFile mapBuf; SumStruct sum = new SumStruct(); long offset = 0; SumSizesSqroot(sum, (UInt64)len); if (len > 0) { mapBuf = new MapFile(fd, (int)len, Options.MAX_MAP_SIZE, (int)sum.bLength); } else { mapBuf = null; } WriteSumHead(f, sum); for (i = 0; i < sum.count; i++) { UInt32 n1 = (UInt32)Math.Min(len, sum.bLength); int off = mapBuf.MapPtr((int)offset, (int)n1); byte[] map = mapBuf.p; UInt32 sum1 = CheckSum.GetChecksum1(map, off, (int)n1); byte[] sum2 = new byte[CheckSum.SUM_LENGTH]; sum2 = checkSum.GetChecksum2(map, off, (int)n1); if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] offset=" + offset + " len=" + n1 + " sum1=" + sum1); } f.writeInt((int)sum1); f.Write(sum2, 0, sum.s2Length); len -= n1; offset += n1; } if (mapBuf != null) { mapBuf = null; } }
public void sendFileEntry(FileStruct file, IOStream f, UInt32 baseflags) { UInt32 flags = baseflags; int l1 = 0,l2 = 0; if(f == null) return; if(file == null) { f.writeByte(0); lastName = ""; return; } string fileName = file.FNameTo().Replace(":",""); 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 */ f.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; f.writeByte((byte)flags); } if ((flags & Options.XMIT_SAME_NAME) != 0) f.writeByte((byte)l1); if ((flags & Options.XMIT_LONG_NAME) != 0) f.writeInt(l2); else f.writeByte((byte)l2); byte[] b =System.Text.ASCIIEncoding.ASCII.GetBytes(fileName); f.Write(b, l1, l2); f.WriteLongInt(file.length); if ((flags & Options.XMIT_SAME_TIME) == 0) f.writeInt(file.modTime.Second); if ((flags & Options.XMIT_SAME_MODE) == 0) f.writeInt((int)file.mode); if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0) { f.writeInt(file.uid); } if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0) { f.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 ) { f.Write(sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH); } } lastName = fileName; }
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); }
public void ReceiveGenerator(string fileName, FileStruct file, int i, IOStream f) { fileName = Path.Combine(options.dir, fileName); if (UnchangedFile(fileName, file)) { return; } if (options.verbose > 2) { Log.WriteLine("Receive Generator(" + fileName + "," + i + ")\n"); } int statRet; FStat st = new FStat(); if (options.dryRun) { statRet = -1; } else { statRet = 0; try { FileInfo fi = new FileInfo(fileName); // TODO: path length st.size = fi.Length; // TODO: path length st.mTime = fi.LastWriteTime; } catch { statRet = -1; } } if (options.onlyExisting && statRet == -1) { /* we only want to update existing files */ if (options.verbose > 1) { Log.WriteLine("not creating new file \"" + fileName + "\""); } return; } string fNameCmp = fileName; if (options.wholeFile > 0) { f.writeInt(i); WriteSumHead(f, null); return; } FileStream fd; try { fd = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read); } catch { if (options.verbose > 3) { Log.WriteLine("failed to open " + Util.fullFileName(fNameCmp) + ", continuing"); } f.writeInt(i); WriteSumHead(f, null); return; } if (options.verbose > 3) { Log.WriteLine("gen mapped " + fNameCmp + " of size " + st.size); } if (options.verbose > 2) { Log.WriteLine("generating and sending sums for " + i); } f.writeInt(i); Stream fCopy = null; GenerateAndSendSums(fd, st.size, f, fCopy); if (fCopy != null) { fCopy.Close(); } fd.Close(); }
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"); } }
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)); }
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(); } }
public void SimpleSendToken(IOStream f,int token, MapFile buf, int offset, int n) { if (n > 0) { int l = 0; while (l < n) { int n1 = Math.Min(Match.CHUNK_SIZE,n-l); f.writeInt(n1); int off = buf.MapPtr(offset + l, n1); f.Write(buf.p, off, n1); l += n1; } } if (token != -2) f.writeInt(-(token+1)); }
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; }
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); }
public void SendExcludeList(IOStream f) { if (options.listOnly && !options.recurse) AddExclude(ref options.excludeList,"/*/*",0); foreach (ExcludeStruct ent in options.excludeList) { int l; string p; if(ent.pattern.Length == 0 || ent.pattern.Length > Options.MAXPATHLEN) continue; l = ent.pattern.Length; p = ent.pattern; if ((ent.matchFlags & Options.MATCHFLG_DIRECTORY) != 0) { p += "/\0"; } if ((ent.matchFlags & Options.MATCHFLG_INCLUDE) != 0) { f.writeInt(l + 2); f.IOPrintf("+ "); } else if ((p[0] == '-' || p[0] == '+') && p[1] == ' ') { f.writeInt(l + 2); f.IOPrintf("- "); } else f.writeInt(l); f.IOPrintf(p); } f.writeInt(0); }
public int ReceiveFiles(ClientInfo clientInfo, List <FileStruct> fileList, string localName) { FStat st = new FStat(); FileStruct file; IOStream ioStream = clientInfo.IoStream; string fileName; string fNameCmp = String.Empty, fNameTmp = String.Empty; bool saveMakeBackups = options.makeBackups; int i, phase = 0; bool recv_ok; if (options.verbose > 2) { Log.WriteLine("ReceiveFiles(" + fileList.Count + ") starting"); } while (true) { i = ioStream.readInt(); if (i == -1) { if (phase != 0) { break; } phase = 1; checkSum.length = CheckSum.SUM_LENGTH; if (options.verbose > 2) { Log.WriteLine("ReceiveFiles phase=" + phase); } ioStream.writeInt(0); //send_msg DONE if (options.keepPartial) { options.makeBackups = false; } continue; } if (i < 0 || i >= fileList.Count) { MainClass.Exit("Invalid file index " + i + " in receiveFiles (count=" + fileList.Count + ")", clientInfo); } file = (fileList[i]); Options.stats.currentFileIndex = i; Options.stats.numTransferredFiles++; Options.stats.totalTransferredSize += file.length; if (localName != null && localName.CompareTo(String.Empty) != 0) { fileName = localName; } else { fileName = Path.Combine(options.dir, LocalizePath(clientInfo, file.GetFullName().Replace(":", String.Empty)).Replace("\\", "/")); //fileName = Path.Combine(options.dir, file.FNameTo().Replace(":",String.Empty)).Replace("\\", "/"); // TODO: path length Directory.CreateDirectory(Path.Combine(options.dir, LocalizePath(clientInfo, file.dirName.Replace(":", String.Empty))).Replace("\\", "/")); Log.WriteLine(Path.Combine(options.dir, file.dirName)); //FileSystem.Directory.CreateDirectory(Path.Combine(options.dir,file.dirName.Replace(":",String.Empty)).Replace("\\", "/")); } if (options.dryRun) { if (!options.amServer && options.verbose > 0) { Log.WriteLine(fileName); } continue; } if (options.verbose > 2) { Log.WriteLine("receiveFiles(" + fileName + ")"); } if (options.partialDir != null && options.partialDir.CompareTo(String.Empty) != 0) { } else { fNameCmp = fileName; } FileStream fd1 = null; try { fd1 = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read); } catch (FileNotFoundException) { fNameCmp = fileName; try { fd1 = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read); } catch (FileNotFoundException) { } } catch (Exception e) { Log.Write(e.Message); } try { FileInfo fi = new FileInfo(fNameCmp); // TODO: path length st.size = fi.Length; } catch { } String tempFileName = getTmpName(fileName); FileStream fd2 = null; fd2 = new FileStream(tempFileName, FileMode.OpenOrCreate, FileAccess.Write); if (!options.amServer && options.verbose > 0) { Log.WriteLine(fileName); } /* recv file data */ recv_ok = ReceiveData(clientInfo, fNameCmp, fd1, st.size, fileName, fd2, file.length); if (fd1 != null) { fd1.Close(); } if (fd2 != null) { fd2.Close(); } // TODO: path length File.Copy(tempFileName, fileName, true); // TODO: path length File.Delete(tempFileName); if (recv_ok || options.inplace) { FinishTransfer(fileName, fNameTmp, file, recv_ok); } } options.makeBackups = saveMakeBackups; if (options.deleteAfter && options.recurse && localName == null && fileList.Count > 0) { DeleteFiles(fileList); } if (options.verbose > 2) { Log.WriteLine("ReceiveFiles finished"); } return(0); }