Example #1
0
        protected bool MoveToFinal(MBFile output, MBFile tempdest, IBuildContext ctxt)
        {
            // We should probably move away the file before clobbering it ...

            if (output.Exists(ctxt))
            {
                output.Delete(ctxt);
            }

            tempdest.MoveTo(output, ctxt);
            return(false);
        }
Example #2
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);
        }