<commit_before>package filestore

import (
	"os"
	"path/filepath"

	"github.com/nightlyone/lockfile"
	"github.com/tus/tusd"
)

type FileLocker struct {
	// Relative or absolute path to store the locks in.
	Path string
}

func (locker FileLocker) LockUpload(id string) error {
	lock, err := locker.newLock(id)
	if err != nil {
		return err
	}

	err = lock.TryLock()
	if err == lockfile.ErrBusy {
		return tusd.ErrFileLocked
	}

	return err
}<commit_msg>Add documentation for FileLocker<commit_after>package filestore

import (
	"os"
	"path/filepath"

	"github.com/nightlyone/lockfile"
	"github.com/tus/tusd"
)

// FileLocker provides an exclusive upload locking mechansim using lock files
// which are stored on disk. Each of them stores the PID of the process which
// aquired the lock. This allows locks to be automatically freed when a process
// is unable to release it on its own because the process is not alive anymore.
//
// Please consult the package lockingstore for instructions on how to use this
// locker.
type FileLocker struct {
	// Relative or absolute path to store the locks in.
	Path string
}

func (locker FileLocker) LockUpload(id string) error {
	lock, err := locker.newLock(id)
	if err != nil {
		return err
	}

	err = lock.TryLock()
	if err == lockfile.ErrBusy {
		return tusd.ErrFileLocked
	}

	return err
}
{'fraction_non_alphanumeric': 0.09009009009009009, 'fraction_numerical': 0.0, 'mean_word_length': 3.6771929824561402, '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': '5792344', 'n_tokens_mistral': 457, 'n_tokens_neox': 440, 'n_words': 157}