func (s *Snap) Install(targetPath, mountDir string) error { // ensure mount-point and blob target dir. for _, dir := range []string{mountDir, filepath.Dir(targetPath)} { if err := os.MkdirAll(dir, 0755); err != nil { return err } } // This is required so that the tests can simulate a mounted // snap when we "install" a squashfs snap in the tests. // We can not mount it for real in the tests, so we just unpack // it to the location which is good enough for the tests. if os.Getenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS") != "" { if err := s.Unpack("*", mountDir); err != nil { return err } } // nothing to do, happens on e.g. first-boot when we already // booted with the OS snap but its also in the seed.yaml if s.path == targetPath || osutil.FilesAreEqual(s.path, targetPath) { return nil } // FIXME: cp.CopyFile() has no preserve attribute flag yet return runCommand("cp", "-a", s.path, targetPath) }
func (s *Snap) Install(targetPath, mountDir string) error { // ensure mount-point and blob target dir. for _, dir := range []string{mountDir, filepath.Dir(targetPath)} { if err := os.MkdirAll(dir, 0755); err != nil { return err } } // This is required so that the tests can simulate a mounted // snap when we "install" a squashfs snap in the tests. // We can not mount it for real in the tests, so we just unpack // it to the location which is good enough for the tests. if os.Getenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS") != "" { if err := s.Unpack("*", mountDir); err != nil { return err } } // nothing to do, happens on e.g. first-boot when we already // booted with the OS snap but its also in the seed.yaml if s.path == targetPath || osutil.FilesAreEqual(s.path, targetPath) { return nil } // try to (hard)link the file, but go on to trying to copy it // if it fails for whatever reason // // link(2) returns EPERM on filesystems that don't support // hard links (like vfat), so checking the error here doesn't // make sense vs just trying to copy it. if err := os.Link(s.path, targetPath); err == nil { return nil } return osutil.CopyFile(s.path, targetPath, osutil.CopyFlagPreserveAll|osutil.CopyFlagSync) }