public static void CopyFile(string Source, string Dest, bool bIsUpload) { if (RemoteToolChain.bUseRPCUtil) { if (bIsUpload) { RPCUtility.CommandHelper.RPCUpload(GetSocket(), Source, Dest); } else { RPCUtility.CommandHelper.RPCDownload(GetSocket(), Source, Dest); } } else { if (bIsUpload) { RemoteToolChain.UploadFile(Source, Dest); } else { RemoteToolChain.DownloadFile(Source, Dest); } } }
public static void BatchFileInfo(FileItem[] Files) { if (RemoteToolChain.bUseRPCUtil) { // build a list of file paths to get info about StringBuilder FileList = new StringBuilder(); foreach (FileItem File in Files) { FileList.AppendFormat("{0}\n", File.AbsolutePath); } DateTime Now = DateTime.Now; // execute the command! Int64[] FileSizeAndDates = RPCUtility.CommandHelper.RPCBatchFileInfo(GetSocket(), FileList.ToString()); Console.WriteLine("BatchFileInfo version 1 took {0}", (DateTime.Now - Now).ToString()); // now update the source times for (int Index = 0; Index < Files.Length; Index++) { Files[Index].Length = FileSizeAndDates[Index * 2 + 0]; Files[Index].LastWriteTime = new DateTimeOffset(RPCUtility.CommandHelper.FromRemoteTime(FileSizeAndDates[Index * 2 + 1])); Files[Index].bExists = FileSizeAndDates[Index * 2 + 0] >= 0; } } else { // build a list of file paths to get info about StringBuilder Commands = new StringBuilder(); Commands.Append("#!/bin/bash\n"); foreach (FileItem File in Files) { Commands.AppendFormat("if [ -e \"{0}\" ]; then eval $(stat -s \"{0}\") && echo $st_mtime && echo $st_size; else echo 0 && echo -1; fi\n", File.AbsolutePath); } // write out locally string LocalCommandsFile = Path.GetTempFileName(); System.IO.File.WriteAllText(LocalCommandsFile, Commands.ToString()); string RemoteDir = "/var/tmp/" + Environment.MachineName; string RemoteCommandsFile = Path.GetFileName(LocalCommandsFile) + ".sh"; DateTime Now = DateTime.Now; RemoteToolChain.UploadFile(LocalCommandsFile, RemoteDir + "/" + RemoteCommandsFile); // execute the file, not a commandline Hashtable Results = Command(RemoteDir, "sh", RemoteCommandsFile + " && rm " + RemoteCommandsFile, null); Console.WriteLine("BatchFileInfo took {0}", (DateTime.Now - Now).ToString()); string[] Lines = ((string)Results["CommandOutput"]).Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (Lines.Length != Files.Length * 2) { throw new BuildException("Received the wrong number of results from BatchFileInfo"); } for (int Index = 0; Index < Files.Length; Index++) { Files[Index].LastWriteTime = new DateTimeOffset(RemoteToLocalTime(Lines[Index * 2 + 0])); Files[Index].Length = long.Parse(Lines[Index * 2 + 1]); Files[Index].bExists = Files[Index].Length >= 0; } } }