Esempio n. 1
0
        public void LinkFromOrCopyTo(MBFile f, IBuildContext ctxt)
        {
            // FIXME: like MakeExecutable, probably a hack.
            string path = GetPath(ctxt);

            if (!RuntimeEnvironment.MonoUnixSupported)
            {
                // emulate with copying
                CopyTo(f, ctxt);
                return;
            }

            // Try and emulate the copy semantics by obliterating
            // f if it already exists.

            string other = f.GetPath(ctxt);

            try {
                File.Delete(other);
            } catch (IOException) {
            }

            // FIXME: does this create absolute paths always?
            // that would be highly lame.

            UnixFileInfo ufi = new UnixFileInfo(path);

            ctxt.Logger.Log("io.file_link", other + " -> " + path);
            ufi.CreateSymbolicLink(other);
        }
Esempio n. 2
0
        public void MoveTo(MBFile dest, IBuildContext ctxt)
        {
            // FIXME: exception handling
            string src = GetPath(ctxt);
            string dp  = dest.GetPath(ctxt);

            ctxt.Logger.Log("io.file_move", src + " -> " + dp);
            File.Move(src, dp);

            this.Dir  = dest.Dir;
            this.Name = dest.Name;
        }
Esempio n. 3
0
		public void LinkFromOrCopyTo (MBFile f, IBuildContext ctxt)
		{
		    // FIXME: like MakeExecutable, probably a hack.
		    string path = GetPath (ctxt);

		    if (!RuntimeEnvironment.MonoUnixSupported) {
			// emulate with copying
			CopyTo (f, ctxt);
			return;
		    }

		    // Try and emulate the copy semantics by obliterating
		    // f if it already exists.

		    string other = f.GetPath (ctxt);

		    try {
			File.Delete (other);
		    } catch (IOException) {
		    }

		    // FIXME: does this create absolute paths always?
		    // that would be highly lame.

		    UnixFileInfo ufi = new UnixFileInfo (path);
		    ctxt.Logger.Log ("io.file_link", other + " -> " + path);
		    ufi.CreateSymbolicLink (other);
		}
Esempio n. 4
0
		public void CopyTo (MBFile f, IBuildContext ctxt) {
			CopyToUnsafe (f.GetPath (ctxt), ctxt);
		}
Esempio n. 5
0
		public void MoveTo (MBFile dest, IBuildContext ctxt) {
			// FIXME: exception handling
			string src = GetPath (ctxt);
			string dp = dest.GetPath (ctxt);

			ctxt.Logger.Log ("io.file_move", src + " -> " + dp);
			File.Move (src, dp);

			this.Dir = dest.Dir;
			this.Name = dest.Name;
		}
Esempio n. 6
0
		protected bool CopyFile (MBFile src, bool backwards, IBuildContext ctxt) {
		    MBFile dest = MakeDestination (src, ctxt);

		    if (dest == null)
			return true;
		       
		    if (PreCopy (src, dest, backwards, ctxt))
			// Error will be reported
			return true;
		    
		    try {
			if (backwards) {
			    // FIXME: delete containing dirs if empty? probably a bad idea.
			    dest.Delete (ctxt);
			} else {
			    dest.Dir.CreateTo (ctxt);
			    src.CopyTo (dest, ctxt);
			}
		    } catch (IOException ioex) {
			string t1;
			
			if (backwards)
			    t1 = String.Format ("There was an error deleting {0}.", dest.GetPath (ctxt));
			else
			    t1 = String.Format ("There was an error copying {0} to {1}.", 
						src.GetPath (ctxt), dest.GetPath (ctxt));
			
			// Different error # for the delete exception?
			ctxt.Logger.Error (3023, t1, ioex.Message);
			return true;
		    } catch (UnauthorizedAccessException uaex) {
			string t1;
			
			if (backwards)
			    t1 = String.Format ("You do not have permission to delete {0}.", 
						dest.GetPath (ctxt));
			else
			    t1 = String.Format ("You do not have permission to copy {0} to {1}.", 
						src.GetPath (ctxt), dest.GetPath (ctxt));
			
			ctxt.Logger.Error (3023, t1, uaex.Message);
			return true;
		    }
		    
		    if (PostCopy (src, dest, backwards, ctxt)) {
			// Error will be reported but we need to clean up
			
			if (!backwards) {
			    try {
				dest.Delete (ctxt);
			    } catch (IOException ioex) {
				string t1 = String.Format ("There was an error removing {0}.", 
							   dest.GetPath (ctxt));
				
				ctxt.Logger.Error (3022, t1, ioex.ToString ());
			    }
			}
			
			return true;
		    }
		    
		    return false;
		}
Esempio n. 7
0
		public static int SaveToolStdout (BinaryInfo info, string extra_args, MBFile stdout, 
						  out string stderr, IBuildContext ctxt) 
		{
		    Stream sout = stdout.OpenWrite (ctxt);
		    StreamWriter wout = new StreamWriter (sout);
		    MemoryStream mserr = new MemoryStream (32);
		    StreamWriter err = new StreamWriter (mserr);

		    int result = Start (info, extra_args, null, wout, err, ctxt);

		    byte[] buf = mserr.ToArray ();
		    stderr = System.Text.Encoding.Default.GetString (buf).Trim ();

		    ctxt.Logger.Log ("launcher.stdout_to", stdout.GetPath (ctxt));
		    ctxt.Logger.Log ("launcher.stderr", stderr);
		    return result;
		}
Esempio n. 8
0
		public static int Start (BinaryInfo info, string extra_args, MBFile stdin, 
					 MBFile stdout, out string stderr, IBuildContext ctxt) {
			MemoryStream ms = new MemoryStream (32);
			StreamReader stdin_stream = null;
			StreamWriter stdout_stream = null;
			StreamWriter stderr_stream = null;
			int exit_code;

			if (stdin != null) {
				stdin_stream = new StreamReader (stdin.OpenRead (ctxt));
				ctxt.Logger.Log ("launcher.stdin_from", stdin.GetPath (ctxt));
			}

			if (stdout != null) {
				stdout_stream = new StreamWriter (stdout.OpenWrite (ctxt));
				ctxt.Logger.Log ("launcher.stdout_to", stdout.GetPath (ctxt));
			}

			stderr_stream = new StreamWriter (ms);

			exit_code = Start (info, extra_args, stdin_stream, stdout_stream,
					   stderr_stream, ctxt);

			byte[] buf = ms.ToArray ();
			stderr = System.Text.Encoding.Default.GetString (buf).Trim ();

			return exit_code;
		}
Esempio n. 9
0
		public static int Start (BinaryInfo info, string extra_args, MBFile stdin, 
					 MBFile stdout, MBFile stderr, IBuildContext ctxt) {
			StreamReader stdin_stream = null;
			StreamWriter stdout_stream = null;
			StreamWriter stderr_stream = null;

			if (stdin != null) {
				stdin_stream = new StreamReader (stdin.OpenRead (ctxt));
				ctxt.Logger.Log ("launcher.stdin_from", stdin.GetPath (ctxt));
			}

			if (stdout != null) {
				stdout_stream = new StreamWriter (stdout.OpenWrite (ctxt));
				ctxt.Logger.Log ("launcher.stdout_to", stdout.GetPath (ctxt));
			}

			if (stderr != null) {
				stderr_stream = new StreamWriter (stderr.OpenWrite (ctxt));
				ctxt.Logger.Log ("launcher.stderr_to", stderr.GetPath (ctxt));
			}

			return Start (info, extra_args, stdin_stream, stdout_stream,
				      stderr_stream, ctxt);
		}
Esempio n. 10
0
 public void CopyTo(MBFile f, IBuildContext ctxt)
 {
     CopyToUnsafe(f.GetPath(ctxt), ctxt);
 }