1 // Copyright (C) 2017 SUSE LLC. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package securejoin 6 7 import "os" 8 9 // In future this should be moved into a separate package, because now there 10 // are several projects (umoci and go-mtree) that are using this sort of 11 // interface. 12 13 // VFS is the minimal interface necessary to use SecureJoinVFS. A nil VFS is 14 // equivalent to using the standard os.* family of functions. This is mainly 15 // used for the purposes of mock testing, but also can be used to otherwise use 16 // SecureJoin with VFS-like system. 17 type VFS interface { 18 // Lstat returns a FileInfo describing the named file. If the file is a 19 // symbolic link, the returned FileInfo describes the symbolic link. Lstat 20 // makes no attempt to follow the link. These semantics are identical to 21 // os.Lstat. 22 Lstat(name string) (os.FileInfo, error) 23 24 // Readlink returns the destination of the named symbolic link. These 25 // semantics are identical to os.Readlink. 26 Readlink(name string) (string, error) 27 } 28 29 // osVFS is the "nil" VFS, in that it just passes everything through to the os 30 // module. 31 type osVFS struct{} 32 33 // Lstat returns a FileInfo describing the named file. If the file is a 34 // symbolic link, the returned FileInfo describes the symbolic link. Lstat 35 // makes no attempt to follow the link. These semantics are identical to 36 // os.Lstat. 37 func (o osVFS) Lstat(name string) (os.FileInfo, error) { return os.Lstat(name) } 38 39 // Readlink returns the destination of the named symbolic link. These 40 // semantics are identical to os.Readlink. 41 func (o osVFS) Readlink(name string) (string, error) { return os.Readlink(name) } 42