protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
        {
            CreateFileOptions newOptions = options & ~CreateFileOptions.CreateConcatenationFile;

            if (!options.HasFlag(CreateFileOptions.CreateConcatenationFile))
            {
                return(BaseFileSystem.CreateFile(path, size, newOptions));
            }

            // A concatenation file directory can't contain normal files
            ReadOnlySpan <byte> parentDir = PathTools.GetParentDirectory(path);

            if (IsConcatenationFile(new U8Span(parentDir)))
            {
                // Cannot create a file inside of a concatenation file
                return(ResultFs.PathNotFound.Log());
            }

            Result rc = BaseFileSystem.CreateDirectory(path, NxFileAttributes.Archive);

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

            long remaining = size;

            for (int i = 0; remaining > 0; i++)
            {
                long fileSize = Math.Min(SubFileSize, remaining);

                FsPath fileName;
                unsafe { _ = &fileName; } // workaround for CS0165

                rc = GetSubFilePath(fileName.Str, path, i);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                Result createSubFileResult = BaseFileSystem.CreateFile(fileName, fileSize, CreateFileOptions.None);

                if (createSubFileResult.IsFailure())
                {
                    BaseFileSystem.DeleteDirectoryRecursively(path);
                    return(createSubFileResult);
                }

                remaining -= fileSize;
            }

            return(Result.Success);
        }
        protected override Result DoCreateDirectory(U8Span path)
        {
            var parent = new U8Span(PathTools.GetParentDirectory(path));

            if (IsConcatenationFile(parent))
            {
                // Cannot create a directory inside of a concatenation file
                return(ResultFs.PathNotFound.Log());
            }

            return(BaseFileSystem.CreateDirectory(path));
        }
Beispiel #3
0
        protected override Result CreateDirectoryImpl(string path)
        {
            path = PathTools.Normalize(path);
            string parent = PathTools.GetParentDirectory(path);

            if (IsConcatenationFile(parent))
            {
                // Cannot create a directory inside of a concatenation file
                return(ResultFs.PathNotFound.Log());
            }

            return(BaseFileSystem.CreateDirectory(path));
        }
Beispiel #4
0
        protected override Result CreateFileImpl(string path, long size, CreateFileOptions options)
        {
            path = PathTools.Normalize(path);

            CreateFileOptions newOptions = options & ~CreateFileOptions.CreateConcatenationFile;

            if (!options.HasFlag(CreateFileOptions.CreateConcatenationFile))
            {
                return(BaseFileSystem.CreateFile(path, size, newOptions));
            }

            // A concatenation file directory can't contain normal files
            string parentDir = PathTools.GetParentDirectory(path);

            if (IsConcatenationFile(parentDir))
            {
                // Cannot create a file inside of a concatenation file
                return(ResultFs.PathNotFound.Log());
            }

            Result rc = BaseFileSystem.CreateDirectory(path, NxFileAttributes.Archive);

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

            long remaining = size;

            for (int i = 0; remaining > 0; i++)
            {
                long   fileSize = Math.Min(SubFileSize, remaining);
                string fileName = GetSubFilePath(path, i);

                Result createSubFileResult = BaseFileSystem.CreateFile(fileName, fileSize, CreateFileOptions.None);

                if (createSubFileResult.IsFailure())
                {
                    BaseFileSystem.DeleteDirectoryRecursively(path);
                    return(createSubFileResult);
                }

                remaining -= fileSize;
            }

            return(Result.Success);
        }