<commit_before>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using Fragile.Internal;
using Fs.Processes.JobObjects;
using Vanara.PInvoke;

namespace Fragile {
    using SafeAllocatedSID = AdvApi32.SafeAllocatedSID;
    using SafeHPIPE = Kernel32.SafeHPIPE;

    [SupportedOSPlatform("windows")]
    public class ProcessRunner : IProcessRunner {
        private readonly ProcessRunnerConfiguration _configuration;        
        private readonly SecurityIdentifier _workingDirectoryAccessCapabilityIdentifier;
        private readonly byte[] _workingDirectoryAccessCapabilitySidBytes;
        private readonly string _exeFilePath;
        private readonly StringBuilder _commandLine;

        private bool _initialSetupCompleted;

        public ProcessRunner(ProcessRunnerConfiguration configuration) {
            _configuration = configuration;

            _workingDirectoryAccessCapabilityIdentifier = new SecurityIdentifier(_configuration.WorkingDirectoryAccessCapabilitySid);
            _workingDirectoryAccessCapabilitySidBytes = new byte[_workingDirectoryAccessCapabilityIdentifier.BinaryLength];
            _workingDirectoryAccessCapabilityIdentifier.GetBinaryForm(_workingDirectoryAccessCapabilitySidBytes, 0);

            _exeFilePath = Path.Combine(_configuration.WorkingDirectoryPath, _configuration.ExeFileName);
            _commandLine = new StringBuilder(_exeFilePath.Length + 2)
                .Append("\"")
                .Append(_exeFilePath)
                .Append("\""); // args not supported yet
        }

        public void InitialSetup() {
            var workingDirectory = new DirectoryInfo(_configuration.WorkingDirectoryPath);
            var workingDirectorySecurity = workingDirectory.GetAccessControl();
            workingDirectorySecurity.AddAccessRule(new FileSystemAccessRule(
                _workingDirectoryAccessCapabilityIdentifier,
                FileSystemRights.Read,
                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                PropagationFlags.None,
                AccessControlType.Allow
            ));
            workingDirectory.SetAccessControl(workingDirectorySecurity);
            _initialSetupCompleted = true;
        }

        public IProcessContainer StartProcess() {
            if (!_initialSetupCompleted)
                throw new InvalidOperationException("InitialSetup must be called before Run.");<commit_msg>[gh-724] Suspend folder permission grant (should move to infra setup)<commit_after>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using Fragile.Internal;
using Fs.Processes.JobObjects;
using Vanara.PInvoke;

namespace Fragile {
    using SafeAllocatedSID = AdvApi32.SafeAllocatedSID;
    using SafeHPIPE = Kernel32.SafeHPIPE;

    [SupportedOSPlatform("windows")]
    public class ProcessRunner : IProcessRunner {
        private readonly ProcessRunnerConfiguration _configuration;        
        private readonly SecurityIdentifier _workingDirectoryAccessCapabilityIdentifier;
        private readonly byte[] _workingDirectoryAccessCapabilitySidBytes;
        private readonly string _exeFilePath;
        private readonly StringBuilder _commandLine;

        private bool _initialSetupCompleted;

        public ProcessRunner(ProcessRunnerConfiguration configuration) {
            _configuration = configuration;

            _workingDirectoryAccessCapabilityIdentifier = new SecurityIdentifier(_configuration.WorkingDirectoryAccessCapabilitySid);
            _workingDirectoryAccessCapabilitySidBytes = new byte[_workingDirectoryAccessCapabilityIdentifier.BinaryLength];
            _workingDirectoryAccessCapabilityIdentifier.GetBinaryForm(_workingDirectoryAccessCapabilitySidBytes, 0);

            _exeFilePath = Path.Combine(_configuration.WorkingDirectoryPath, _configuration.ExeFileName);
            _commandLine = new StringBuilder(_exeFilePath.Length + 2)
                .Append("\"")
                .Append(_exeFilePath)
                .Append("\""); // args not supported yet
        }

        public void InitialSetup() {
            /*var workingDirectory = new DirectoryInfo(_configuration.WorkingDirectoryPath);
            var workingDirectorySecurity = workingDirectory.GetAccessControl();
            workingDirectorySecurity.AddAccessRule(new FileSystemAccessRule(
                _workingDirectoryAccessCapabilityIdentifier,
                FileSystemRights.Read,
                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                PropagationFlags.None,
                AccessControlType.Allow
            ));
            workingDirectory.SetAccessControl(workingDirectorySecurity);*/
            _initialSetupCompleted = true;
        }

        public IProcessContainer StartProcess() {
            if (!_initialSetupCompleted)
                throw new InvalidOperationException("InitialSetup must be called before Run.");
{'fraction_non_alphanumeric': 0.06069146937241639, 'fraction_numerical': 0.002818489289740699, 'mean_word_length': 3.3524121013900245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4733503', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1147, 'n_words': 250}