<commit_before>// Package vfs is for storing files on the cozy, including binary ones like
// photos and movies. The range of possible operations with this endpoint goes
// from simple ones, like uploading a file, to more complex ones, like renaming
// a directory. It also ensure that an instance is not exceeding its quota, and
// keeps a trash to recover files recently deleted.
package vfs

import (
	"errors"
	"io"
	mimetype "mime"
	"os"
	"path"
	"strings"
	"time"

	"github.com/cozy/cozy-stack/pkg/consts"
)

// DefaultContentType is used for files uploaded with no content-type
const DefaultContentType = "application/octet-stream"

// ForbiddenFilenameChars is the list of forbidden characters in a filename.
const ForbiddenFilenameChars = "/\x00"

const (
	// TrashDirName is the path of the trash directory
	TrashDirName = "/.cozy_trash"
	// AppsDirName is the path of the directory in which apps are stored
	AppsDirName = "/.cozy_apps"
)

const (
	conflictSuffix = " (__cozy__: "
	conflictFormat = "%s (__cozy__: %s)"
)

// ErrSkipDir is used in WalkFn as an error to skip the current
// directory. It is not returned by any function of the package.
var ErrSkipDir = errors.New("skip directories")

// Fs is an interface providing a set of high-level methods to interact with
// the file-system binaries and metadata.
type Fs interface {
	InitFs() error
	Delete() error

	// CreateDir is used to create a new directory from its document.
	CreateDir(doc *DirDoc) error
	// UpdateDir is used to update the document of a directory. It takes the new
	// file document that you want to create. It can also take the old document,
	// representing the current revision of the file. In this case it will try to
	// modify the file, otherwise it will create it.
	//
	// Warning: you MUST call the Close() method and check for its error.
	CreateFile(newdoc, olddoc *FileDoc) (File, error)
	// DestroyDirContent destroys all directories and files contained in a
	// directory.
	DestroyDirContent(doc *DirDoc) error
	// DestroyDirAndContent destroys all directories and files contained in a
	// directory and the directory itself.
	DestroyDirAndContent(doc *DirDoc) error
	// DestroyFile  destroys a file from the trash.
	DestroyFile(doc *FileDoc) error
	// OpenFile return a file handler for reading associated with the given file
	// document. The file handler implements io.ReadCloser and io.Seeker.
	OpenFile(doc *FileDoc) (File, error)
}

// File is a reader, writer, seeker, closer iterface reprsenting an opened
// file for reading or writing.
type File interface {
	io.Reader
	io.Seeker
	io.Writer
	io.Closer
}

// Indexer is an interface providing a common set of method for indexing layer
// of our VFS.
//
// An indexer is typically responsible for storing and indexing the files and
// directories metadata, as well as caching them if necessary.
type Indexer interface {
	InitIndex() error

	// DiskUsage computes the total size of the files contained in the VFS.
	DiskUsage() (int64, error)

	CreateFileDoc(doc *FileDoc) error
	UpdateFileDoc(olddoc, newdoc *FileDoc) error
	DeleteFileDoc(doc *FileDoc) error

	CreateDirDoc(doc *DirDoc) error
	UpdateDirDoc(olddoc, newdoc *DirDoc) error
	DeleteDirDoc(doc *DirDoc) error

	// DirByID returns the directory document information associated with the
	// specified identifier.
	DirByID(fileID string) (*DirDoc, error)
	// DirByPath returns the directory document information associated with the
	// specified path.
	DirByPath(name string) (*DirDoc, error)<commit_msg>Update comments from Indexer interface<commit_after>// Package vfs is for storing files on the cozy, including binary ones like
// photos and movies. The range of possible operations with this endpoint goes
// from simple ones, like uploading a file, to more complex ones, like renaming
// a directory. It also ensure that an instance is not exceeding its quota, and
// keeps a trash to recover files recently deleted.
package vfs

import (
	"errors"
	"io"
	mimetype "mime"
	"os"
	"path"
	"strings"
	"time"

	"github.com/cozy/cozy-stack/pkg/consts"
)

// DefaultContentType is used for files uploaded with no content-type
const DefaultContentType = "application/octet-stream"

// ForbiddenFilenameChars is the list of forbidden characters in a filename.
const ForbiddenFilenameChars = "/\x00"

const (
	// TrashDirName is the path of the trash directory
	TrashDirName = "/.cozy_trash"
	// AppsDirName is the path of the directory in which apps are stored
	AppsDirName = "/.cozy_apps"
)

const (
	conflictSuffix = " (__cozy__: "
	conflictFormat = "%s (__cozy__: %s)"
)

// ErrSkipDir is used in WalkFn as an error to skip the current
// directory. It is not returned by any function of the package.
var ErrSkipDir = errors.New("skip directories")

// Fs is an interface providing a set of high-level methods to interact with
// the file-system binaries and metadata.
type Fs interface {
	InitFs() error
	Delete() error

	// CreateDir is used to create a new directory from its document.
	CreateDir(doc *DirDoc) error
	//
	//
	// Warning: you MUST call the Close() method and check for its error.
	CreateFile(newdoc, olddoc *FileDoc) (File, error)
	// DestroyDirContent destroys all directories and files contained in a
	// directory.
	DestroyDirContent(doc *DirDoc) error
	// DestroyDirAndContent destroys all directories and files contained in a
	// directory and the directory itself.
	DestroyDirAndContent(doc *DirDoc) error
	// DestroyFile  destroys a file from the trash.
	DestroyFile(doc *FileDoc) error
	// OpenFile return a file handler for reading associated with the given file
	// document. The file handler implements io.ReadCloser and io.Seeker.
	OpenFile(doc *FileDoc) (File, error)
}

// File is a reader, writer, seeker, closer iterface reprsenting an opened
// file for reading or writing.
type File interface {
	io.Reader
	io.Seeker
	io.Writer
	io.Closer
}

// Indexer is an interface providing a common set of method for indexing layer
// of our VFS.
//
// An indexer is typically responsible for storing and indexing the files and
// directories metadata, as well as caching them if necessary.
type Indexer interface {
	InitIndex() error

	// DiskUsage computes the total size of the files contained in the VFS.
	DiskUsage() (int64, error)

	// CreateFileDoc creates and add in the index a new file document.
	CreateFileDoc(doc *FileDoc) error
	// UpdateFileDocx is used to update the document of a file. It takes the
	// new file document that you want to create and the old document,
	// representing the current revision of the file.
	UpdateFileDoc(olddoc, newdoc *FileDoc) error
	// DeleteFileDoc removes from the index the specified file document.
	DeleteFileDoc(doc *FileDoc) error

	// CreateDirDoc creates and add in the index a new directory document.
	CreateDirDoc(doc *DirDoc) error
	// UpdateDirDoc is used to update the document of a directory. It takes the new
	// directory document that you want to create and the old document,
	// representing the current revision of the directory.
	UpdateDirDoc(olddoc, newdoc *DirDoc) error
	// DeleteDirDoc removes from the index the specified directory document.
	DeleteDirDoc(doc *DirDoc) error

	// DirByID returns the directory document information associated with the
	// specified identifier.
	DirByID(fileID string) (*DirDoc, error)
	// DirByPath returns the directory document information associated with the
	// specified path.
	DirByPath(name string) (*DirDoc, error)
{'fraction_non_alphanumeric': 0.07413354743744145, 'fraction_numerical': 0.001070520540612873, 'mean_word_length': 3.9398545935228024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1403061', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2093, 'n_words': 971}