Esempio n. 1
0
        public async Task <Result <Directory> > GetParentDir(FileSystemPath path)
        {
            if (_path.IsParentOf(path))
            {
                return(Result.OK(this));
            }

            var parent = path.ParentPath;

            while (!_path.IsParentOf(parent))
            {
                if (parent.IsRoot)
                {
                    return(new KeyNotFound <Directory>("Path does not belong to this tree."));
                }
                parent = parent.ParentPath;
            }

            var dirResult = await DirectoryFactory.GetOrAddAsync(path.Path);

            if (!dirResult.HasValue)
            {
                return(dirResult);
            }

            return(await dirResult.Value.GetParentDir(path));
        }
Esempio n. 2
0
        public async Task <Result <Directory> > FindDirectoryAsync(FileSystemPath path)
        {
            var info = await FindDirectoryInfoAsync(path);

            if (!info.HasValue)
            {
                return(new KeyNotFound <Directory>(info.ErrorMsg));
            }

            var dirResult = await DirectoryFactory.GetOrAddAsync(path.Path, info.Value.Locator);

            return(dirResult);
        }
Esempio n. 3
0
        public static Result <FileSystem> GetOrAdd(string root)
        {
            var path = FileSystemPath.Parse(root);

            if (!path.IsRoot)
            {
                return(new InvalidOperation <FileSystem>("Must be root path"));
            }

            var dir = DirectoryFactory.GetOrAddAsync(root).GetAwaiter().GetResult();

            if (!dir.HasValue)
            {
                return(Result.Fail <FileSystem>(dir.ErrorCode.Value, dir.ErrorMsg));
            }
            return(Result.OK(new FileSystem(dir.Value)));
        }
Esempio n. 4
0
        public async Task <Result <Directory> > CreateSubDirectory(FileSystemPath path)
        {
            // validate that parent path is
            if (!_path.IsParentOf(path))
            {
                return(new InvalidOperation <Directory>("Incorrect path"));
            }
            if (!path.IsDirectory)
            {
                return(new InvalidOperation <Directory>("Path is not a directory"));
            }

            var directoryResult = await FindDirectoryAsync(path);

            if (directoryResult.HasValue)
            {
                return(new ValueAlreadyExists <Directory>(path.Path));
            }

            var res = await DirectoryFactory.GetOrAddAsync(path.Path);

            if (!res.HasValue)
            {
                return(res);
            }

            await AddOrLoad(DIR_INFO_KEY);

            var info = SetupDirectoryInfo(path, res.Value._info);

            var value   = new StoredValue(info.Locator);
            var pointer = await _dataTreeCache[DIR_INFO_KEY].AddAsync(path.Path, value);

            if (!pointer.HasValue)
            {
                return(Result.Fail <Directory>(pointer.ErrorCode.Value, pointer.ErrorMsg));
            }

            await _indexer.IndexAsync(path.Path, pointer.Value);

            //ScheduleIndexing(path, pointer.Value);

            return(res);
        }