<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;

namespace TeamCityBackup
{
    public class Clean
    {
        private readonly Options options;

        public Clean(Options options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            this.options = options;
        }

        public bool Run()
        {
            if (!Directory.Exists(options.BackupDirectory))
            {
                Console.Error.WriteLine("The backup directory '{0}' does not exist.", options.BackupDirectory);
                return false;
            }

            Console.WriteLine("Cleaning backup directory '{0}'", options.BackupDirectory);

            try
            {
                var directoryInfo = new DirectoryInfo(options.BackupDirectory);

                IEnumerable<FileInfo> filesToRemove = directoryInfo.GetFiles()
                    .OrderByDescending(file => file.CreationTimeUtc)
                    .Skip(options.MaxBackupCount - 1);

                foreach (FileInfo file in filesToRemove)
                {
                    Console.WriteLine("Deleting backup file {0}", file.Name);
                    file.Delete();
                }

                return true;
            }
            catch (SecurityException e)
            {
                WriteErrorMessage(e);
                return false;
            }
            catch (IOException e)
            {
                WriteErrorMessage(e);
                return false;
            }
            catch (ArgumentException e)
            {
                WriteErrorMessage(e);
                return false;
            }
        }

        private static void WriteErrorMessage(Exception e)
        {
            Console.Error.WriteLine("Error occurred when cleaning backup directory." + Environment.NewLine + e);
        }
    }
}<commit_msg>Minor cosmetic change.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;

namespace TeamCityBackup
{
    public class Clean
    {
        private readonly Options options;

        public Clean(Options options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            this.options = options;
        }

        public bool Run()
        {
            if (!Directory.Exists(options.BackupDirectory))
            {
                Console.Error.WriteLine("The backup directory '{0}' does not exist.", options.BackupDirectory);
                return false;
            }

            Console.WriteLine("Cleaning backup directory '{0}'", options.BackupDirectory);

            try
            {
                var directoryInfo = new DirectoryInfo(options.BackupDirectory);

                IEnumerable<FileInfo> filesToRemove = directoryInfo.GetFiles()
                    .OrderByDescending(file => file.CreationTimeUtc)
                    .Skip(options.MaxBackupCount - 1);

                foreach (FileInfo file in filesToRemove)
                {
                    Console.WriteLine("Deleting old backup file '{0}'", file.Name);
                    file.Delete();
                }

                return true;
            }
            catch (SecurityException e)
            {
                WriteErrorMessage(e);
                return false;
            }
            catch (IOException e)
            {
                WriteErrorMessage(e);
                return false;
            }
            catch (ArgumentException e)
            {
                WriteErrorMessage(e);
                return false;
            }
        }

        private static void WriteErrorMessage(Exception e)
        {
            Console.Error.WriteLine("Error occurred when cleaning backup directory." + Environment.NewLine + e);
        }
    }
}
{'fraction_non_alphanumeric': 0.07835912552198478, 'fraction_numerical': 0.0019651191353475803, 'mean_word_length': 1.3044708545557442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4638534', 'n_tokens_mistral': 941, 'n_tokens_neox': 876, 'n_words': 215}