Esempio n. 1
0
        public static bool SaveCachedArtifacts(Hash128 hash, string[] artifactPaths, string rootPath)
        {
            var path = GetPathForCachedArtifacts(hash);

            var result = true;

            try
            {
                Directory.CreateDirectory(path);
                foreach (var artifact in artifactPaths)
                {
                    var source = string.Format("{0}/{1}", rootPath, artifact);
                    if (!File.Exists(source))
                    {
                        BuildLogger.LogWarning("Unable to find source file '{0}' to add to the build cache.", artifact);
                        result = false;
                        continue;
                    }
                    else if (result)
                    {
                        var copyToPath = string.Format("{0}/{1}", path, artifact);
                        var directory  = Path.GetDirectoryName(copyToPath);
                        Directory.CreateDirectory(directory);
                        File.Copy(source, copyToPath, true);
                    }
                }
            }
            catch (Exception)
            {
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
                return(false);
            }

            if (!result && Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            return(result);
        }
Esempio n. 2
0
        public static bool ValidOutputFolder(string outputFolder, bool logError)
        {
            if (string.IsNullOrEmpty(outputFolder))
            {
                if (logError)
                {
                    BuildLogger.LogError(kPathNotValidError, outputFolder);
                }
                return(false);
            }

            var fullOutputPath = NormalizePath(outputFolder);

            foreach (var path in kInvalidPaths)
            {
                if (fullOutputPath == path)
                {
                    if (logError)
                    {
                        BuildLogger.LogError(kPathNotValidError, outputFolder);
                    }
                    return(false);
                }
            }

            foreach (var path in kInvalidRegexPaths)
            {
                if (Regex.IsMatch(fullOutputPath, path))
                {
                    if (logError)
                    {
                        BuildLogger.LogError(kPathNotValidError, outputFolder);
                    }
                    return(false);
                }
            }
            return(true);
        }