예제 #1
0
        public Task FullDataDirectory()
        {
            var path = GetStringQueryString("path", required: false);
            var name = GetStringQueryString("name", required: false);

            var baseDataDirectory = ServerStore.Configuration.Core.DataDirectory.FullPath;

            // 1. Used as default when both Name & Path are Not defined
            var result = baseDataDirectory;

            // 2. Path defined, Path overrides any given Name
            if (string.IsNullOrEmpty(path) == false)
            {
                result = PathUtil.ToFullPath(path, baseDataDirectory);
            }

            // 3. Name defined, No path
            else if (string.IsNullOrEmpty(name) == false)
            {
                // 'Databases' prefix is added...
                result = RavenConfiguration.GetDataDirectoryPath(ServerStore.Configuration.Core, name, ResourceType.Database);
            }

            using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("FullPath");
                    writer.WriteString(result);
                    writer.WriteEndObject();
                }

            return(Task.CompletedTask);
        }
예제 #2
0
        private bool IsDefaultDataDirectory(string dataDirectory, string databaseName)
        {
            var defaultDataDirectory = RavenConfiguration.GetDataDirectoryPath(
                _serverStore.Configuration.Core,
                databaseName,
                ResourceType.Database);

            return(PlatformDetails.RunningOnPosix == false
                ? string.Equals(defaultDataDirectory, dataDirectory, StringComparison.OrdinalIgnoreCase)
                : string.Equals(defaultDataDirectory, dataDirectory, StringComparison.Ordinal));
        }
예제 #3
0
        public async Task FullDataDirectory()
        {
            var path = GetStringQueryString("path", required: false);
            var name = GetStringQueryString("name", required: false);
            var requestTimeoutInMs = GetIntValueQueryString("requestTimeoutInMs", required: false) ?? 5 * 1000;

            var baseDataDirectory = ServerStore.Configuration.Core.DataDirectory.FullPath;

            // 1. Used as default when both Name & Path are Not defined
            var    result = baseDataDirectory;
            string error  = null;

            try
            {
                // 2. Path defined, Path overrides any given Name
                if (string.IsNullOrEmpty(path) == false)
                {
                    result = new PathSetting(path, baseDataDirectory).FullPath;
                }

                // 3. Name defined, No path
                else if (string.IsNullOrEmpty(name) == false)
                {
                    // 'Databases' prefix is added...
                    result = RavenConfiguration.GetDataDirectoryPath(ServerStore.Configuration.Core, name, ResourceType.Database);
                }

                if (ServerStore.Configuration.Core.EnforceDataDirectoryPath)
                {
                    if (PathUtil.IsSubDirectory(result, ServerStore.Configuration.Core.DataDirectory.FullPath) == false)
                    {
                        error = $"The administrator has restricted databases to be created only " +
                                $"under the {RavenConfiguration.GetKey(x => x.Core.DataDirectory)} " +
                                $"directory: '{ServerStore.Configuration.Core.DataDirectory.FullPath}'.";
                    }
                }
            }
            catch (Exception e)
            {
                error = e.Message;
            }

            var getNodesInfo = GetBoolValueQueryString("getNodesInfo", required: false) ?? false;
            var info         = new DataDirectoryInfo(ServerStore, result, name, isBackup: false, getNodesInfo, requestTimeoutInMs, ResponseBodyStream());
            await info.UpdateDirectoryResult(databaseName : null, error : error);
        }
예제 #4
0
        private string GetDataDirectory()
        {
            var dataDirectory =
                RavenConfiguration.GetDataDirectoryPath(
                    _serverStore.Configuration.Core,
                    RestoreFromConfiguration.DatabaseName,
                    ResourceType.Database);

            var i = 0;

            while (HasFilesOrDirectories(dataDirectory))
            {
                dataDirectory += $"-{++i}";
            }

            return(dataDirectory);
        }