Example #1
0
        private static bool TryLoadFileOrFolderList(Enlistment enlistment, string valueString, string listFileName, bool readListFromStdIn, bool isFolder, List <string> output, Func <string, string> elementValidationFunction, out string error)
        {
            output.AddRange(
                GetFilesFromVerbParameter(valueString)
                .Union(GetFilesFromFile(listFileName, out string fileReadError))
                .Union(GetFilesFromStdin(readListFromStdIn))
                .Where(path => !path.StartsWith(GVFSConstants.GitCommentSign.ToString()))
                .Where(path => !string.IsNullOrWhiteSpace(path))
                .Select(path => BlobPrefetcher.ToAbsolutePath(enlistment, path, isFolder: isFolder)));

            if (!string.IsNullOrWhiteSpace(fileReadError))
            {
                error = fileReadError;
                return(false);
            }

            string[] errorArray = output
                                  .Select(elementValidationFunction)
                                  .Where(s => !string.IsNullOrWhiteSpace(s))
                                  .ToArray();

            if (errorArray != null && errorArray.Length > 0)
            {
                error = string.Join("\n", errorArray);
                return(false);
            }

            error = null;
            return(true);
        }
Example #2
0
        public static bool TryLoadFileList(Enlistment enlistment, string filesInput, List <string> fileListOutput, out string error)
        {
            fileListOutput.AddRange(
                filesInput.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(path => BlobPrefetcher.ToAbsolutePath(enlistment, path, isFolder: false)));

            foreach (string file in fileListOutput)
            {
                if (file.IndexOf('*', 1) != -1)
                {
                    error = "Only prefix wildcards are supported. Invalid entry: " + file;
                    return(false);
                }

                if (file.EndsWith(GVFSConstants.GitPathSeparatorString) ||
                    file.EndsWith(pathSeparatorString))
                {
                    error = "Folders are not allowed in the file list. Invalid entry: " + file;
                    return(false);
                }
            }

            error = null;
            return(true);
        }
Example #3
0
        public static bool TryLoadFolderList(Enlistment enlistment, string foldersInput, string folderListFile, List <string> folderListOutput, out string error)
        {
            folderListOutput.AddRange(
                foldersInput.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(path => BlobPrefetcher.ToAbsolutePath(enlistment, path, isFolder: true)));

            if (!string.IsNullOrWhiteSpace(folderListFile))
            {
                if (File.Exists(folderListFile))
                {
                    IEnumerable <string> allLines = File.ReadAllLines(folderListFile)
                                                    .Select(line => line.Trim())
                                                    .Where(line => !string.IsNullOrEmpty(line))
                                                    .Where(line => !line.StartsWith(GVFSConstants.GitCommentSign.ToString()))
                                                    .Select(path => BlobPrefetcher.ToAbsolutePath(enlistment, path, isFolder: true));

                    folderListOutput.AddRange(allLines);
                }
                else
                {
                    error = string.Format("Could not find '{0}' for folder list.", folderListFile);
                    return(false);
                }
            }

            folderListOutput.RemoveAll(string.IsNullOrWhiteSpace);

            foreach (string folder in folderListOutput)
            {
                if (folder.Contains("*"))
                {
                    error = "Wildcards are not supported for folders. Invalid entry: " + folder;
                    return(false);
                }
            }

            error = null;
            return(true);
        }