Exemple #1
0
        private void ProcessDirectory(LocalDirectory parentDirectory, IO.DirectoryInfo directoryInfo)
        {
            if (parentDirectory == null)
            {
                throw new ArgumentNullException(nameof(parentDirectory));
            }

            if (directoryInfo == null)
            {
                throw new ArgumentNullException(nameof(directoryInfo));
            }

            try
            {
                LocalDirectory directory = (LocalDirectory)parentDirectory.GetSubdirectory(directoryInfo.Name);

                if (directory == null)
                {
                    directory = parentDirectory.CreateSubDirectory(directoryInfo.Name, directoryInfo.FullName);
                }

                foreach (var fileInfo in directoryInfo.EnumerateFiles().Where(f => !f.Name.StartsWith(".")))
                {
                    IndexingFile?.Invoke(this, new FilenameEventArgs(fileInfo.FullName));

                    LocalFile file = (LocalFile)directory.GetFile(fileInfo.Name);
                    if (file == null)
                    {
                        file = directory.CreateFile(fileInfo);
                    }
                    else
                    {
                        // XXX: Update file info
                    }

                    if (string.IsNullOrEmpty(file.InfoHash))
                    {
                        this.hasher.HashFile(file);
                    }
                }

                foreach (var subDirectoryInfo in directoryInfo.EnumerateDirectories().Where(d => !d.Name.StartsWith(".")))
                {
                    //ProcessDirectory(directory, subDirectoryInfo);
                    this.queue.Add(new QueueItem(directory, subDirectoryInfo), this.cancellation.Token);
                }
            }
            catch (ThreadAbortException)
            {
                // Canceled, ignore error.
            }
            catch (Exception ex)
            {
                this.loggingService.LogError("Error while re-indexing shared files:", ex);

                ErrorIndexing?.Invoke(this, new ErrorEventArgs(ex));
            }
        }
        public void RemoveItems(IEnumerable<ConflictInfo> conflicts)
        {
            if (conflicts == null)
            {
                throw new ArgumentNullException(nameof(conflicts));
            }

            conflicts = conflicts.ToArray();

            if (!conflicts.Any())
            {
                return;
            }

            if (!GitGroup.Repository.LocalBranchExists(BranchName))
            {
                throw new ItemNotFoundException($"There is no ConflictInfo for file '{conflicts.First().FilePath}'");
            }


            var root = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);

            // verify conflicts
            foreach (var conflict in conflicts)
            {             
                var relativePath = GetRelativeConflictInfoFilePath(conflict.FilePath);
                if (!root.FileExists(relativePath))
                {
                    throw new ItemNotFoundException($"There is no ConflictInfo for file '{conflict.FilePath}'");
                }
            }


            // delete conflict info files
            using (var workingDirectory = new TemporaryWorkingDirectory(GitGroup.Repository.Info.Path, BranchName.ToString()))
            {
                var localDirectory= new LocalDirectory(null, workingDirectory.Location);

                foreach (var conflict in conflicts)
                {
                    var relativePath = GetRelativeConflictInfoFilePath(conflict.FilePath);
                    System.IO.File.Delete(((ILocalFile)localDirectory.GetFile(relativePath)).Location);
                }

                workingDirectory.Commit($"{nameof(GitConflictService)}: Removed {conflicts.Count()} items");
                workingDirectory.Push();
            }                
        }