示例#1
0
        protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
        {
            UnsafeHelpers.SkipParamInit(out file);

            Result rc = ResolveFullPath(out string fullPath, path, true);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetEntryType(out DirectoryEntryType entryType, path);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (entryType == DirectoryEntryType.Directory)
            {
                return(ResultFs.PathNotFound.Log());
            }

            FileStream fileStream = null;

            rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() =>
                                                                OpenFileInternal(out fileStream, fullPath, mode), _fsClient);
            if (rc.IsFailure())
            {
                return(rc);
            }

            file = new LocalFile(fileStream, mode);
            return(Result.Success);
        }
示例#2
0
        protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
        {
            UnsafeHelpers.SkipParamInit(out directory);
            Result rc = ResolveFullPath(out string fullPath, path, true);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetDirInfo(out DirectoryInfo dirInfo, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!dirInfo.Attributes.HasFlag(FileAttributes.Directory))
            {
                return(ResultFs.PathNotFound.Log());
            }

            IDirectory dirTemp = null;

            rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() =>
                                                                OpenDirectoryInternal(out dirTemp, mode, dirInfo), _fsClient);
            if (rc.IsFailure())
            {
                return(rc);
            }

            directory = dirTemp;
            return(Result.Success);
        }
示例#3
0
        protected override Result DoDeleteFile(U8Span path)
        {
            Result rc = ResolveFullPath(out string fullPath, path, true);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetFileInfo(out FileInfo file, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            return(TargetLockedAvoidance.RetryToAvoidTargetLocked(
                       () => DeleteFileInternal(file), _fsClient));
        }
示例#4
0
        protected override Result DoDeleteDirectoryRecursively(U8Span path)
        {
            Result rc = ResolveFullPath(out string fullPath, path, true);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetDirInfo(out DirectoryInfo dir, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            return(TargetLockedAvoidance.RetryToAvoidTargetLocked(
                       () => DeleteDirectoryInternal(dir, true), _fsClient));
        }
示例#5
0
        protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
        {
            Result rc = CheckSubPath(oldPath, newPath);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = ResolveFullPath(out string fullCurrentPath, oldPath, true);
            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = ResolveFullPath(out string fullNewPath, newPath, false);
            if (rc.IsFailure())
            {
                return(rc);
            }

            // Official FS behavior is to do nothing in this case
            if (fullCurrentPath == fullNewPath)
            {
                return(Result.Success);
            }

            rc = GetDirInfo(out DirectoryInfo currentDirInfo, fullCurrentPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetDirInfo(out DirectoryInfo newDirInfo, fullNewPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            return(TargetLockedAvoidance.RetryToAvoidTargetLocked(
                       () => RenameDirInternal(currentDirInfo, newDirInfo), _fsClient));
        }