<commit_before>﻿//
// Copyright (c) 2008-2011, <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

namespace DiscUtils.SquashFs
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.IO.Compression;
    using DiscUtils.Compression;

    /// <summary>
    /// Class that creates SquashFs file systems.
    /// </summary>
    public sealed class SquashFileSystemBuilder
    {
        private const int DefaultBlockSize = 131072;

        private BuilderDirectory _rootDir;
        private BuilderContext _context;
        private uint _nextInode;

        /// <summary>
        /// Initializes a new instance of the SquashFileSystemBuilder class.
        /// </summary>
        public SquashFileSystemBuilder()
        {
            DefaultFilePermissions = UnixFilePermissions.OwnerRead | UnixFilePermissions.OwnerWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupWrite;
            DefaultDirectoryPermissions = UnixFilePermissions.OwnerAll | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupExecute | UnixFilePermissions.OthersRead | UnixFilePermissions.OthersExecute;
            DefaultUser = 0;
            DefaultGroup = 0;
        }

        /// <summary>
        /// Gets and sets the default permissions used for new files.
        /// </summary>
        public UnixFilePermissions DefaultFilePermissions
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the default permissions used for new directories.
        /// </summary>
        public UnixFilePermissions DefaultDirectoryPermissions
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the default user id used for new files and directories.
        /// </summary>
        public int DefaultUser
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the default group id used for new files and directories.
        /// </summary>
        public int DefaultGroup
        {
            get;
            set;
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="content">The content of the file.</param>
        /// <remarks>
        /// <para>The created file with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created, with default owner, group and directory permissions.</para>
        /// </remarks>
        public void AddFile(string path, Stream content)
        {
            AddFile(path, content, DefaultUser, DefaultGroup, DefaultFilePermissions, DateTime.Now);
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="contentPath">Local file system path to the file to add.</param>
        /// <remarks>
        /// <para>The created file with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with default owner, group and directory permissions.</para>
        /// </remarks>
        public void AddFile(string path, string contentPath)
        {
            AddFile(path, contentPath, DefaultUser, DefaultGroup, DefaultFilePermissions, DateTime.Now);
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="content">The content of the file.</param>
        /// <param name="user">The owner of the file.</param>
        /// <param name="group">The group of the file.</param>
        /// <param name="permissions">The access permission of the file.</param>
        /// <param name="modificationTime">The modification time of the file</param>
        /// <remarks>
        /// <para>Any missing parent directories will be created with the specified owner and group,
        /// default directory permissions and the current time as the modification time.</para>
        /// </remarks>
        public void AddFile(string path, Stream content, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderFile file = new BuilderFile(content);
            file.UserId = user;
            file.GroupId = group;
            file.Mode = permissions;
            file.ModificationTime = modificationTime;

            BuilderDirectory dirNode = CreateDirectory(
                Utilities.GetDirectoryFromPath(path),
                user,
                group,
                DefaultDirectoryPermissions);
            dirNode.AddChild(Utilities.GetFileFromPath(path), file);
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="contentPath">Local file system path to the file to add.</param>
        /// <param name="user">The owner of the file.</param>
        /// <param name="group">The group of the file.</param>
        /// <param name="permissions">The access permission of the file.</param>
        /// <param name="modificationTime">The modification time of the file</param>
        /// <remarks>
        /// <para>Any missing parent directories will be created with the specified owner and group,
        /// default directory permissions and the current time as the modification time.</para>
        /// </remarks>
        public void AddFile(string path, string contentPath, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderFile file = new BuilderFile(contentPath);
            file.UserId = user;
            file.GroupId = group;
            file.Mode = permissions;
            file.ModificationTime = modificationTime;

            BuilderDirectory dirNode = CreateDirectory(
                Utilities.GetDirectoryFromPath(path),
                user,
                group,
                DefaultDirectoryPermissions);
            dirNode.AddChild(Utilities.GetFileFromPath(path), file);
        }

        /// <summary>
        /// Adds a directory to the file system.
        /// </summary>
        /// <param name="path">The full path to the directory.</param>
        /// <remarks>
        /// <para>The created directory with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with default owner, group and directory permissions.</para>
        /// </remarks>
        public void AddDirectory(string path)
        {
            AddDirectory(path, DefaultUser, DefaultGroup, DefaultDirectoryPermissions, DateTime.Now);
        }

        /// <summary>
        /// Adds a directory to the file system.
        /// </summary>
        /// <param name="path">The full path to the directory.</param>
        /// <remarks>
        /// <para>The created directory with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with the specified owner, group, and directory permissions.  The current time
        /// will be used as the modification time.</para>
        /// </remarks>
        public void AddDirectory(string path, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderDirectory dir = new BuilderDirectory();<commit_msg>SquashFs: Fix documentation on AddDirectory.<commit_after>﻿//
// Copyright (c) 2008-2011, <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

namespace DiscUtils.SquashFs
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.IO.Compression;
    using DiscUtils.Compression;

    /// <summary>
    /// Class that creates SquashFs file systems.
    /// </summary>
    public sealed class SquashFileSystemBuilder
    {
        private const int DefaultBlockSize = 131072;

        private BuilderDirectory _rootDir;
        private BuilderContext _context;
        private uint _nextInode;

        /// <summary>
        /// Initializes a new instance of the SquashFileSystemBuilder class.
        /// </summary>
        public SquashFileSystemBuilder()
        {
            DefaultFilePermissions = UnixFilePermissions.OwnerRead | UnixFilePermissions.OwnerWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupWrite;
            DefaultDirectoryPermissions = UnixFilePermissions.OwnerAll | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupExecute | UnixFilePermissions.OthersRead | UnixFilePermissions.OthersExecute;
            DefaultUser = 0;
            DefaultGroup = 0;
        }

        /// <summary>
        /// Gets and sets the default permissions used for new files.
        /// </summary>
        public UnixFilePermissions DefaultFilePermissions
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the default permissions used for new directories.
        /// </summary>
        public UnixFilePermissions DefaultDirectoryPermissions
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the default user id used for new files and directories.
        /// </summary>
        public int DefaultUser
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the default group id used for new files and directories.
        /// </summary>
        public int DefaultGroup
        {
            get;
            set;
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="content">The content of the file.</param>
        /// <remarks>
        /// <para>The created file with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created, with default owner, group and directory permissions.</para>
        /// </remarks>
        public void AddFile(string path, Stream content)
        {
            AddFile(path, content, DefaultUser, DefaultGroup, DefaultFilePermissions, DateTime.Now);
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="contentPath">Local file system path to the file to add.</param>
        /// <remarks>
        /// <para>The created file with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with default owner, group and directory permissions.</para>
        /// </remarks>
        public void AddFile(string path, string contentPath)
        {
            AddFile(path, contentPath, DefaultUser, DefaultGroup, DefaultFilePermissions, DateTime.Now);
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="content">The content of the file.</param>
        /// <param name="user">The owner of the file.</param>
        /// <param name="group">The group of the file.</param>
        /// <param name="permissions">The access permission of the file.</param>
        /// <param name="modificationTime">The modification time of the file</param>
        /// <remarks>
        /// <para>Any missing parent directories will be created with the specified owner and group,
        /// default directory permissions and the current time as the modification time.</para>
        /// </remarks>
        public void AddFile(string path, Stream content, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderFile file = new BuilderFile(content);
            file.UserId = user;
            file.GroupId = group;
            file.Mode = permissions;
            file.ModificationTime = modificationTime;

            BuilderDirectory dirNode = CreateDirectory(
                Utilities.GetDirectoryFromPath(path),
                user,
                group,
                DefaultDirectoryPermissions);
            dirNode.AddChild(Utilities.GetFileFromPath(path), file);
        }

        /// <summary>
        /// Adds a file to the file system.
        /// </summary>
        /// <param name="path">The full path to the file.</param>
        /// <param name="contentPath">Local file system path to the file to add.</param>
        /// <param name="user">The owner of the file.</param>
        /// <param name="group">The group of the file.</param>
        /// <param name="permissions">The access permission of the file.</param>
        /// <param name="modificationTime">The modification time of the file</param>
        /// <remarks>
        /// <para>Any missing parent directories will be created with the specified owner and group,
        /// default directory permissions and the current time as the modification time.</para>
        /// </remarks>
        public void AddFile(string path, string contentPath, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderFile file = new BuilderFile(contentPath);
            file.UserId = user;
            file.GroupId = group;
            file.Mode = permissions;
            file.ModificationTime = modificationTime;

            BuilderDirectory dirNode = CreateDirectory(
                Utilities.GetDirectoryFromPath(path),
                user,
                group,
                DefaultDirectoryPermissions);
            dirNode.AddChild(Utilities.GetFileFromPath(path), file);
        }

        /// <summary>
        /// Adds a directory to the file system.
        /// </summary>
        /// <param name="path">The full path to the directory.</param>
        /// <remarks>
        /// <para>The created directory with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with default owner, group and directory permissions.</para>
        /// </remarks>
        public void AddDirectory(string path)
        {
            AddDirectory(path, DefaultUser, DefaultGroup, DefaultDirectoryPermissions, DateTime.Now);
        }

        /// <summary>
        /// Adds a directory to the file system.
        /// </summary>
        /// <param name="path">The full path to the directory.</param>
        /// <param name="user">The owner of the directory.</param>
        /// <param name="group">The group of the directory.</param>
        /// <param name="permissions">The access permission of the directory.</param>
        /// <param name="modificationTime">The modification time of the directory.</param>
        /// <remarks>
        /// <para>The created directory with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with the specified owner, group, and directory permissions.  The current time
        /// will be used as the modification time.</para>
        /// </remarks>
        public void AddDirectory(string path, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderDirectory dir = new BuilderDirectory();
{'fraction_non_alphanumeric': 0.09811446687802436, 'fraction_numerical': 0.0017798542744312809, 'mean_word_length': 2.116117850953206, 'pattern_counts': {'":': 0, '<': 181, '<?xml version=': 0, '>': 181, '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': '6632594', 'n_tokens_mistral': 4274, 'n_tokens_neox': 4173, 'n_words': 1637}