From 0c6951fcd2b285c995b18cd1acaed8d80abe5ccf Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 11 Jun 2014 20:03:34 +0400 Subject: [PATCH] When linking, check that inode file matches if linking to same file. #65 Otherwise files from conflicting packages might override each other in the published pool. This is explicitly POSIX-only. --- files/public.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/files/public.go b/files/public.go index 4891d793..ed68d44b 100644 --- a/files/public.go +++ b/files/public.go @@ -1,10 +1,12 @@ package files import ( + "fmt" "github.com/smira/aptly/aptly" "github.com/smira/aptly/utils" "os" "path/filepath" + "syscall" ) // PublishedStorage abstract file system with public dirs (published repos) @@ -71,8 +73,23 @@ func (storage *PublishedStorage) LinkFromPool(publishedDirectory string, sourceP return err } - _, err = os.Stat(filepath.Join(poolPath, baseName)) - if err == nil { // already exists, skip + var dstStat, srcStat os.FileInfo + + dstStat, err = os.Stat(filepath.Join(poolPath, baseName)) + if err == nil { + // already exists, check source file + srcStat, err = os.Stat(sourcePath) + if err != nil { + // source file doesn't exist? problem! + return err + } + + srcSys := srcStat.Sys().(*syscall.Stat_t) + dstSys := dstStat.Sys().(*syscall.Stat_t) + + if srcSys.Ino != dstSys.Ino { + return fmt.Errorf("error linking file to %s: file already exists and is different", filepath.Join(poolPath, baseName)) + } return nil }