<commit_before>// Copyright (c) 2015, <NAME>. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.

package repoctl

import (
	"os"
	"path"

	"github.com/goulash/errs"
	"github.com/goulash/osutil"
	pu "github.com/goulash/pacman/pkgutil"
)

// Link tries to hard link the file, and failing that, copies it over.
func (r *Repo) Link(h errs.Handler, pkgfiles ...string) error {
	return r.add(h, pkgfiles, linkFile, "linking")
}

// TODO: Get this in the osutil package.
func linkFile(src, dst string) error {
	// Before we delete dst, make sure src exists!
	if ex, err := osutil.FileExists(src); !ex {
		if err != nil {
			return err
		}
		return &NotExistsError{src}
	}

	// Check if dst exists, so we can delete prior to linking.
	if ex, err := osutil.FileExists(dst); !ex {
		if err != nil {
			return err
		}
	} else {
		err = os.Remove(dst)
		if err != nil {
			return err
		}
	}

	err := os.Link(src, dst)
	if err != nil {<commit_msg>Do not delete destination file before hard-linking<commit_after>// Copyright (c) 2015, <NAME>. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.

package repoctl

import (
	"os"
	"path"

	"github.com/goulash/errs"
	"github.com/goulash/osutil"
	pu "github.com/goulash/pacman/pkgutil"
)

// Link tries to hard link the file, and failing that, copies it over.
func (r *Repo) Link(h errs.Handler, pkgfiles ...string) error {
	return r.add(h, pkgfiles, linkFile, "linking")
}

// TODO: Get this in the osutil package.
func linkFile(src, dst string) error {
	err := os.Link(src, dst)
	if err != nil {
{'fraction_non_alphanumeric': 0.12709832134292565, 'fraction_numerical': 0.004796163069544364, 'mean_word_length': 3.290488431876607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7262863', 'n_tokens_mistral': 619, 'n_tokens_neox': 584, 'n_words': 215}