<commit_before>package server

import (
	"os"

	"golang.org/x/net/context"

	"github.com/RoaringBitmap/roaring"
	"github.com/coreos/agro"
	"github.com/coreos/agro/blockset"
	"github.com/coreos/agro/models"
)

func (s *server) Rename(from, to agro.Path) error {
	if from.Volume != to.Volume {
		return agro.ErrInvalid
	}
	newINodeID, err := s.mds.CommitINodeIndex(from.Volume)
	if err != nil {
		return err
	}
	inode, _, err := s.updateINodeChain(from, func(inode *models.INode, vol agro.VolumeID) (*models.INode, agro.INodeRef, error) {
		if inode == nil {
			return nil, agro.NewINodeRef(vol, newINodeID), os.ErrNotExist
		}
		inode.INode = uint64(newINodeID)
		var newFilenames []string
		for _, x := range inode.Filenames {
			if x == from.Path {
				newFilenames = append(newFilenames, to.Path)
				continue
			}
			newFilenames = append(newFilenames, x)
		}
		inode.Filenames = newFilenames
		return inode, agro.NewINodeRef(vol, newINodeID), nil
	})
	if err != nil {
		return err
	}
	err = s.mds.SetFileEntry(from, &models.FileEntry{})
	if err != nil {
		return err
	}
	return s.mds.SetFileEntry(to, &models.FileEntry{
		Chain: inode.Chain,
	})
}

func (s *server) Link(p agro.Path, new agro.Path) error {
	if p.Volume != new.Volume {
		return agro.ErrInvalid
	}
	newINodeID, err := s.mds.CommitINodeIndex(p.Volume)
	if err != nil {
		return err
	}
	inode, _, err := s.updateINodeChain(p, func(inode *models.INode, vol agro.VolumeID) (*models.INode, agro.INodeRef, error) {
		if inode == nil {
			return nil, agro.NewINodeRef(vol, newINodeID), os.ErrNotExist
		}
		inode.INode = uint64(newINodeID)
		inode.Filenames = append(inode.Filenames, p.Path)
		return inode, agro.NewINodeRef(vol, newINodeID), nil
	})
	if err != nil {
		return err
	}
	return s.mds.SetFileEntry(new, &models.FileEntry{
		Chain: inode.Chain,
	})
}

func (s *server) Symlink(to string, new agro.Path) error {
	_, ent, err := s.FileEntryForPath(new)
	if err != nil && err != os.ErrNotExist {
		return err
	}
	if err != os.ErrNotExist {
		clog.Error(ent, err)
		if ent.Chain != 0 {
			return agro.ErrExists
		}
	}
	return s.mds.SetFileEntry(new, &models.FileEntry{
		Sympath: to,
	})
}
<commit_msg>fix hardlink<commit_after>package server

import (
	"os"

	"golang.org/x/net/context"

	"github.com/RoaringBitmap/roaring"
	"github.com/coreos/agro"
	"github.com/coreos/agro/blockset"
	"github.com/coreos/agro/models"
)

func (s *server) Rename(from, to agro.Path) error {
	if from.Volume != to.Volume {
		return agro.ErrInvalid
	}
	newINodeID, err := s.mds.CommitINodeIndex(from.Volume)
	if err != nil {
		return err
	}
	inode, _, err := s.updateINodeChain(from, func(inode *models.INode, vol agro.VolumeID) (*models.INode, agro.INodeRef, error) {
		if inode == nil {
			return nil, agro.NewINodeRef(vol, newINodeID), os.ErrNotExist
		}
		inode.INode = uint64(newINodeID)
		var newFilenames []string
		for _, x := range inode.Filenames {
			if x == from.Path {
				newFilenames = append(newFilenames, to.Path)
				continue
			}
			newFilenames = append(newFilenames, x)
		}
		inode.Filenames = newFilenames
		return inode, agro.NewINodeRef(vol, newINodeID), nil
	})
	if err != nil {
		return err
	}
	err = s.mds.SetFileEntry(from, &models.FileEntry{})
	if err != nil {
		return err
	}
	return s.mds.SetFileEntry(to, &models.FileEntry{
		Chain: inode.Chain,
	})
}

func (s *server) Link(p agro.Path, new agro.Path) error {
	if p.Volume != new.Volume {
		return agro.ErrInvalid
	}
	newINodeID, err := s.mds.CommitINodeIndex(p.Volume)
	if err != nil {
		return err
	}
	inode, _, err := s.updateINodeChain(p, func(inode *models.INode, vol agro.VolumeID) (*models.INode, agro.INodeRef, error) {
		if inode == nil {
			return nil, agro.NewINodeRef(vol, newINodeID), os.ErrNotExist
		}
		inode.INode = uint64(newINodeID)
		inode.Filenames = append(inode.Filenames, new.Path)
		return inode, agro.NewINodeRef(vol, newINodeID), nil
	})
	if err != nil {
		return err
	}
	return s.mds.SetFileEntry(new, &models.FileEntry{
		Chain: inode.Chain,
	})
}

func (s *server) Symlink(to string, new agro.Path) error {
	_, ent, err := s.FileEntryForPath(new)
	if err != nil && err != os.ErrNotExist {
		return err
	}
	if err != os.ErrNotExist {
		clog.Error(ent, err)
		if ent.Chain != 0 {
			return agro.ErrExists
		}
	}
	return s.mds.SetFileEntry(new, &models.FileEntry{
		Sympath: to,
	})
}

{'fraction_non_alphanumeric': 0.14170692431561996, 'fraction_numerical': 0.002300437083045779, 'mean_word_length': 3.705627705627706, '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': '5346950', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1758, 'n_words': 367}