<commit_before>backupApp.directive('backupEditUri', function() {
  return {
    restrict: 'E',
    scope: {
    	uri: '=uri',
    	hide: '=hide'
    },
    templateUrl: 'templates/edituri.html',
    controller: function($scope, AppService, AppUtils, SystemInfo, EditUriBackendConfig, EditUriBuiltins) {

		var scope = $scope;
		var backenddataloaders = angular.copy(EditUriBackendConfig.loaders);

		var builduri = function() {

			if (EditUriBackendConfig.validaters[scope.Backend.Key] == null) {
				
				if (!EditUriBackendConfig.defaultvalidater(scope))
					return;

			} else {
				
				if (!EditUriBackendConfig.validaters[scope.Backend.Key](scope))
					return;
			}

			if (EditUriBackendConfig.builders[scope.Backend.Key] == null)
				return EditUriBackendConfig.defaultbuilder(scope);
			else
				return EditUriBackendConfig.builders[scope.Backend.Key](scope);
		}

		$scope.testConnection = function() {
			var res = builduri();
			if (res) {

                var hasTriedCreate = false;
                var hasTriedCert = false;

                var testConnection = function() {
                	scope.Testing = true;
                	AppService.post('/remoteoperation/test', res).then(function() {
                		scope.Testing = false;
                		alert('Connection worked!');
                	}, handleError);
                };

                var createFolder = function() {
                	scope.Testing = true;
                	AppService.post('/remoteoperation/create', res).then(testConnection, handleError);
                };

                var handleError = function(data) {

                	scope.Testing = false;
                	var message = data.statusText;

                    if (!hasTriedCreate && message == 'missing-folder')
                    {
                        if (confirm('The folder ' + scope.Folder + ' does not exist\nCreate it now?')) {
                            createFolder();
                        }
                    }
                    else if (!hasTriedCert && message.indexOf('incorrect-cert:') == 0)
                    {
                        var hash = message.substr('incorrect-cert:'.length);
                        if (confirm('The server certificate could not be validated.\nDo you want to approve the SSL certificate with the hash: ' + hash + '?' )) {

                            hasTriedCert = true;
                            scope.AdvancedOptions += '\r\n--accept-specified-ssl-hash=' + hash;

                            testConnection();
                        }
                    }
                    else
                        alert('Failed to connect: ' + message);
                }

                testConnection();
			}
		};

		$scope.save = function() {

			var res = builduri();
			if (res) {
				scope.uri = res;
				scope.hide();
			}
		};

		$scope.contains_value = AppUtils.contains_value;

		$scope.$watch('Backend', function() {
			if (scope.Backend == null) {
				$scope.TemplateUrl = null;
				return;
			}

			scope.SupportsSSL = false;
			for(var n in scope.Backend.Options)
				if (scope.Backend.Options[n].Name == 'use-ssl')
					scope.SupportsSSL = true;

			scope.TemplateUrl = EditUriBackendConfig.templates[scope.Backend.Key];
			if (scope.TemplateUrl == null)
				scope.TemplateUrl = EditUriBackendConfig.defaulttemplate;

			if (backenddataloaders[scope.Backend.Key] == null)
				return;

			backenddataloaders[scope.Backend.Key](scope);
		});
<commit_msg>Removed a possible race<commit_after>backupApp.directive('backupEditUri', function() {
  return {
    restrict: 'E',
    scope: {
    	uri: '=uri',
    	hide: '=hide'
    },
    templateUrl: 'templates/edituri.html',
    controller: function($scope, AppService, AppUtils, SystemInfo, EditUriBackendConfig, EditUriBuiltins) {

		var scope = $scope;

		var builduri = function() {

			if (EditUriBackendConfig.validaters[scope.Backend.Key] == null) {
				
				if (!EditUriBackendConfig.defaultvalidater(scope))
					return;

			} else {
				
				if (!EditUriBackendConfig.validaters[scope.Backend.Key](scope))
					return;
			}

			if (EditUriBackendConfig.builders[scope.Backend.Key] == null)
				return EditUriBackendConfig.defaultbuilder(scope);
			else
				return EditUriBackendConfig.builders[scope.Backend.Key](scope);
		}

		$scope.testConnection = function() {
			var res = builduri();
			if (res) {

                var hasTriedCreate = false;
                var hasTriedCert = false;

                var testConnection = function() {
                	scope.Testing = true;
                	AppService.post('/remoteoperation/test', res).then(function() {
                		scope.Testing = false;
                		alert('Connection worked!');
                	}, handleError);
                };

                var createFolder = function() {
                	scope.Testing = true;
                	AppService.post('/remoteoperation/create', res).then(testConnection, handleError);
                };

                var handleError = function(data) {

                	scope.Testing = false;
                	var message = data.statusText;

                    if (!hasTriedCreate && message == 'missing-folder')
                    {
                        if (confirm('The folder ' + scope.Folder + ' does not exist\nCreate it now?')) {
                            createFolder();
                        }
                    }
                    else if (!hasTriedCert && message.indexOf('incorrect-cert:') == 0)
                    {
                        var hash = message.substr('incorrect-cert:'.length);
                        if (confirm('The server certificate could not be validated.\nDo you want to approve the SSL certificate with the hash: ' + hash + '?' )) {

                            hasTriedCert = true;
                            scope.AdvancedOptions += '\r\n--accept-specified-ssl-hash=' + hash;

                            testConnection();
                        }
                    }
                    else
                        alert('Failed to connect: ' + message);
                }

                testConnection();
			}
		};

		$scope.save = function() {

			var res = builduri();
			if (res) {
				scope.uri = res;
				scope.hide();
			}
		};

		$scope.contains_value = AppUtils.contains_value;

		$scope.$watch('Backend', function() {
			if (scope.Backend == null) {
				$scope.TemplateUrl = null;
				return;
			}

			scope.SupportsSSL = false;
			for(var n in scope.Backend.Options)
				if (scope.Backend.Options[n].Name == 'use-ssl')
					scope.SupportsSSL = true;

			scope.TemplateUrl = EditUriBackendConfig.templates[scope.Backend.Key];
			if (scope.TemplateUrl == null)
				scope.TemplateUrl = EditUriBackendConfig.defaulttemplate;

			if (EditUriBackendConfig.loaders[scope.Backend.Key] == null)
				return;

			EditUriBackendConfig.loaders[scope.Backend.Key](scope);
		});

{'fraction_non_alphanumeric': 0.11740949084090581, 'fraction_numerical': 0.0002884754074715131, 'mean_word_length': 1.7825040128410914, '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': '6720180', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1860, 'n_words': 366}