How to use relPath method of internal Package

Best Ginkgo code snippet using internal.relPath

rfs.go

Source:rfs.go Github

copy

Full Screen

...80 return ""81 }82 return dir83}84// isExcluded finds out if relative ciphertext path "relPath" is excluded85// (used when -exclude is passed by the user)86func (rfs *ReverseFS) isExcluded(relPath string) bool {87 for _, e := range rfs.cExclude {88 // If the root dir is excluded, everything is excluded.89 if e == "" {90 return true91 }92 // This exact path is excluded93 if e == relPath {94 return true95 }96 // Files inside an excluded directory are also excluded97 if strings.HasPrefix(relPath, e+"/") {98 return true99 }100 }101 return false102}103// isDirIV determines if the path points to a gocryptfs.diriv file104func (rfs *ReverseFS) isDirIV(relPath string) bool {105 if rfs.args.PlaintextNames {106 return false107 }108 return filepath.Base(relPath) == nametransform.DirIVFilename109}110// isNameFile determines if the path points to a gocryptfs.longname.*.name111// file112func (rfs *ReverseFS) isNameFile(relPath string) bool {113 if rfs.args.PlaintextNames {114 return false115 }116 fileType := nametransform.NameType(filepath.Base(relPath))117 return fileType == nametransform.LongNameFilename118}119// isTranslatedConfig returns true if the default config file name is in use120// and the ciphertext path is "gocryptfs.conf".121// "gocryptfs.conf" then maps to ".gocryptfs.reverse.conf" in the plaintext122// directory.123func (rfs *ReverseFS) isTranslatedConfig(relPath string) bool {124 if rfs.args.ConfigCustom {125 return false126 }127 if relPath == configfile.ConfDefaultName {128 return true129 }130 return false131}132// GetAttr - FUSE call133// "relPath" is the relative ciphertext path134func (rfs *ReverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) {135 if rfs.isExcluded(relPath) {136 return nil, fuse.ENOENT137 }138 // Handle "gocryptfs.conf"139 if rfs.isTranslatedConfig(relPath) {140 absConfPath, _ := rfs.abs(configfile.ConfReverseName, nil)141 var st syscall.Stat_t142 err := syscall.Lstat(absConfPath, &st)143 if err != nil {144 return nil, fuse.ToStatus(err)145 }146 var a fuse.Attr147 a.FromStat(&st)148 if rfs.args.ForceOwner != nil {149 a.Owner = *rfs.args.ForceOwner150 }151 return &a, fuse.OK152 }153 // Handle virtual files (gocryptfs.diriv, *.name)154 var f nodefs.File155 var status fuse.Status156 virtual := false157 if rfs.isDirIV(relPath) {158 virtual = true159 f, status = rfs.newDirIVFile(relPath)160 }161 if rfs.isNameFile(relPath) {162 virtual = true163 f, status = rfs.newNameFile(relPath)164 }165 if virtual {166 if !status.Ok() {167 tlog.Warn.Printf("GetAttr %q: newXFile failed: %v\n", relPath, status)168 return nil, status169 }170 var a fuse.Attr171 status = f.GetAttr(&a)172 if rfs.args.ForceOwner != nil {173 a.Owner = *rfs.args.ForceOwner174 }175 return &a, status176 }177 dirfd, name, err := rfs.openBackingDir(relPath)178 if err != nil {179 return nil, fuse.ToStatus(err)180 }181 // Stat the backing file/dir using Fstatat182 var st unix.Stat_t183 err = syscallcompat.Fstatat(dirfd, name, &st, unix.AT_SYMLINK_NOFOLLOW)184 syscall.Close(dirfd)185 if err != nil {186 return nil, fuse.ToStatus(err)187 }188 // Instead of risking an inode number collision, we return an error.189 if st.Ino > inoBaseMin {190 tlog.Warn.Printf("GetAttr %q: backing file inode number %d crosses reserved space, max=%d. Returning EOVERFLOW.",191 relPath, st.Ino, inoBaseMin)192 return nil, fuse.ToStatus(syscall.EOVERFLOW)193 }194 var a fuse.Attr195 st2 := syscallcompat.Unix2syscall(st)196 a.FromStat(&st2)197 // Calculate encrypted file size198 if a.IsRegular() {199 a.Size = rfs.contentEnc.PlainSizeToCipherSize(a.Size)200 } else if a.IsSymlink() {201 var linkTarget string202 var readlinkStatus fuse.Status203 linkTarget, readlinkStatus = rfs.Readlink(relPath, context)204 if !readlinkStatus.Ok() {205 return nil, readlinkStatus206 }207 a.Size = uint64(len(linkTarget))208 }209 if rfs.args.ForceOwner != nil {210 a.Owner = *rfs.args.ForceOwner211 }212 return &a, fuse.OK213}214// Access - FUSE call215func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status {216 if rfs.isExcluded(relPath) {217 return fuse.ENOENT218 }219 if rfs.isTranslatedConfig(relPath) || rfs.isDirIV(relPath) || rfs.isNameFile(relPath) {220 // access(2) R_OK flag for checking if the file is readable, always 4 as defined in POSIX.221 ROK := uint32(0x4)222 // Virtual files can always be read and never written223 if mode == ROK || mode == 0 {224 return fuse.OK225 }226 return fuse.EPERM227 }228 dirfd, name, err := rfs.openBackingDir(relPath)229 if err != nil {230 return fuse.ToStatus(err)231 }232 err = syscallcompat.Faccessat(dirfd, name, mode)233 if err != nil {234 fmt.Printf("name=%q err=%v", name, err)235 }236 syscall.Close(dirfd)237 return fuse.ToStatus(err)238}239// Open - FUSE call240func (rfs *ReverseFS) Open(relPath string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {241 if rfs.isExcluded(relPath) {242 return nil, fuse.ENOENT243 }244 if rfs.isTranslatedConfig(relPath) {245 return rfs.loopbackfs.Open(configfile.ConfReverseName, flags, context)246 }247 if rfs.isDirIV(relPath) {248 return rfs.newDirIVFile(relPath)249 }250 if rfs.isNameFile(relPath) {251 return rfs.newNameFile(relPath)252 }253 return rfs.newFile(relPath)254}255func (rfs *ReverseFS) openDirPlaintextnames(relPath string, entries []fuse.DirEntry) ([]fuse.DirEntry, fuse.Status) {256 if relPath != "" || rfs.args.ConfigCustom {257 return entries, fuse.OK258 }259 // We are in the root dir and the default config file name260 // ".gocryptfs.reverse.conf" is used. We map it to "gocryptfs.conf".261 dupe := -1262 status := fuse.OK263 for i := range entries {264 if entries[i].Name == configfile.ConfReverseName {265 entries[i].Name = configfile.ConfDefaultName266 } else if entries[i].Name == configfile.ConfDefaultName {267 dupe = i268 }269 }270 if dupe >= 0 {271 // Warn the user loudly: The gocryptfs.conf_NAME_COLLISION file will272 // throw ENOENT errors that are hard to miss.273 tlog.Warn.Printf("The file %s is mapped to %s and shadows another file. Please rename %s in %s .",274 configfile.ConfReverseName, configfile.ConfDefaultName, configfile.ConfDefaultName, rfs.args.Cipherdir)275 entries[dupe].Name = "gocryptfs.conf_NAME_COLLISION_" + fmt.Sprintf("%d", cryptocore.RandUint64())276 }277 return entries, status278}279// OpenDir - FUSE readdir call280func (rfs *ReverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {281 if rfs.isExcluded(cipherPath) {282 return nil, fuse.ENOENT283 }284 relPath, err := rfs.decryptPath(cipherPath)285 if err != nil {286 return nil, fuse.ToStatus(err)287 }288 // Read plaintext dir289 dirfd, err := syscallcompat.OpenDirNofollow(rfs.args.Cipherdir, filepath.Dir(relPath))290 if err != nil {291 return nil, fuse.ToStatus(err)292 }293 fd, err := syscallcompat.Openat(dirfd, filepath.Base(relPath), syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_NOFOLLOW, 0)294 syscall.Close(dirfd)295 if err != nil {296 return nil, fuse.ToStatus(err)297 }298 entries, err := syscallcompat.Getdents(fd)299 syscall.Close(fd)300 if err != nil {301 return nil, fuse.ToStatus(err)302 }303 if rfs.args.PlaintextNames {304 return rfs.openDirPlaintextnames(cipherPath, entries)305 }306 // Allocate maximum possible number of virtual files.307 // If all files have long names we need a virtual ".name" file for each,308 // plus one for gocryptfs.diriv.309 virtualFiles := make([]fuse.DirEntry, len(entries)+1)310 // Virtual gocryptfs.diriv file311 virtualFiles[0] = fuse.DirEntry{312 Mode: virtualFileMode,313 Name: nametransform.DirIVFilename,314 }315 // Actually used entries316 nVirtual := 1317 // Encrypt names318 dirIV := pathiv.Derive(cipherPath, pathiv.PurposeDirIV)319 for i := range entries {320 var cName string321 // ".gocryptfs.reverse.conf" in the root directory is mapped to "gocryptfs.conf"322 if cipherPath == "" && entries[i].Name == configfile.ConfReverseName {323 cName = configfile.ConfDefaultName324 } else {325 cName = rfs.nameTransform.EncryptName(entries[i].Name, dirIV)326 if len(cName) > unix.NAME_MAX {327 cName = rfs.nameTransform.HashLongName(cName)328 dotNameFile := fuse.DirEntry{329 Mode: virtualFileMode,330 Name: cName + nametransform.LongNameSuffix,331 }332 virtualFiles[nVirtual] = dotNameFile333 nVirtual++334 }335 }336 entries[i].Name = cName337 }338 // Filter out excluded entries339 if rfs.cExclude != nil {340 filtered := make([]fuse.DirEntry, 0, len(entries))341 for _, entry := range entries {342 // filepath.Join handles the case of cipherPath="" correctly:343 // Join("", "foo") -> "foo". This does not: cipherPath + "/" + name"344 p := filepath.Join(cipherPath, entry.Name)345 if rfs.isExcluded(p) {346 // Skip file347 continue348 }349 filtered = append(filtered, entry)350 }351 entries = filtered352 }353 entries = append(entries, virtualFiles[:nVirtual]...)354 return entries, fuse.OK355}356// StatFs - FUSE call. Returns information about the filesystem (free space357// etc).358// Securing statfs against symlink races seems to be more trouble than359// it's worth, so we just ignore the path and always return info about the360// backing storage root dir.361func (rfs *ReverseFS) StatFs(relPath string) *fuse.StatfsOut {362 if rfs.isExcluded(relPath) {363 return nil364 }365 var s syscall.Statfs_t366 err := syscall.Statfs(rfs.args.Cipherdir, &s)367 if err != nil {368 return nil369 }370 out := &fuse.StatfsOut{}371 out.FromStatfsT(&s)372 return out373}374// Readlink - FUSE call375func (rfs *ReverseFS) Readlink(relPath string, context *fuse.Context) (string, fuse.Status) {376 if rfs.isExcluded(relPath) {377 return "", fuse.ENOENT378 }379 dirfd, name, err := rfs.openBackingDir(relPath)380 if err != nil {381 return "", fuse.ToStatus(err)382 }383 // read the link target using Readlinkat384 plainTarget, err := syscallcompat.Readlinkat(dirfd, name)385 syscall.Close(dirfd)386 if err != nil {387 return "", fuse.ToStatus(err)388 }389 if rfs.args.PlaintextNames {390 return plainTarget, fuse.OK391 }392 nonce := pathiv.Derive(relPath, pathiv.PurposeSymlinkIV)393 // Symlinks are encrypted like file contents and base64-encoded394 cBinTarget := rfs.contentEnc.EncryptBlockNonce([]byte(plainTarget), 0, nil, nonce)395 cTarget := rfs.nameTransform.B64.EncodeToString(cBinTarget)396 // The kernel will reject a symlink target above 4096 chars and return397 // and I/O error to the user. Better emit the proper error ourselves.398 if len(cTarget) > syscallcompat.PATH_MAX {399 return "", fuse.Status(syscall.ENAMETOOLONG)400 }401 return cTarget, fuse.OK402}...

Full Screen

Full Screen

file.go

Source:file.go Github

copy

Full Screen

...38 }39 testkit.FatalErrf(t, tp_file.RemoveContents(dir), "failed to remove dir contents [%s]", dir)40}41// CreatePath returns a path under DynamicDataDir() at a relative path built by joining the path parts.42func CreatePath(t *testing.T, pathPart ...string) (relPath string, absPath string) {43 pathPart = append([]string{DynamicDataDir()}, pathPart...)44 relPath = filepath.Join(pathPart...)45 absPath, err := filepath.Abs(relPath)46 testkit.FatalErrf(t, err, "failed to get absolute path [%s]", relPath)47 return relPath, absPath48}49// FixturePath returns a path under FixtureDataDir() at a relative path built by joining the path parts.50func FixturePath(t *testing.T, pathPart ...string) (relPath string, absPath string) {51 pathPart = append([]string{FixtureDataDir()}, pathPart...)52 relPath = filepath.Join(pathPart...)53 absPath, err := filepath.Abs(relPath)54 testkit.FatalErrf(t, err, "failed to get absolute path [%s]", relPath)55 return relPath, absPath56}57// CreateFile creates a file under DynamicDataDir() at a relative path built by joining the path parts.58//59// All parts except the final one are assumed to be ancestor directrories (which are created if needed).60//61// The file is created with 0600. Directories are created with 0700.62func CreateFile(t *testing.T, pathPart ...string) (relPath string, absPath string) {63 relPath, absPath = CreatePath(t, pathPart...)64 _, err := cage_file.CreateFileAll(absPath, 0, 0600, 0700)65 testkit.FatalErrf(t, err, "failed to create file [%s]", absPath)66 return relPath, absPath67}...

Full Screen

Full Screen

relPath

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(filepath.Rel("a/b", "a/b/t/file"))4 fmt.Println(filepath.Rel("a/b", "a/c/t/file"))5 fmt.Println(filepath.Rel("a/b/", "a/b/t/file"))6 fmt.Println(filepath.Rel("a/b/", "a/c/t/file"))7 fmt.Println(filepath.Rel("a/b", "a/b"))8 fmt.Println(filepath.Rel("a/b", "a/b/"))9 fmt.Println(filepath.Rel("a/b/", "a/b"))10 fmt.Println(filepath.Rel("a/b/", "a/b/"))11}12func Rel(basepath, targpath string) (string, error) {13 if basepath == targpath {14 }15 if basepath == "" {16 }17 if targpath == "" {18 }19 base := Clean(basepath)20 target := Clean(targpath)21 if base == target {22 }23 if base == "." {24 }25 if target == "." {26 }

Full Screen

Full Screen

relPath

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(filepath.Rel("/a/b", "/a/b/t/file"))4}5import (6func main() {7 fmt.Println(path.Abs("/a/b/c"))8}9import (10func main() {11 fmt.Println(filepath.Abs("/a/b/c"))12}13import (14func main() {15 fmt.Println(filepath.IsAbs("/a/b/c"))16 fmt.Println(filepath.IsAbs("a/b/c"))17}

Full Screen

Full Screen

relPath

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(filepath.Rel("C:/Users/abc", "C:/Users/abc/def"))4}5import (6func main() {7 fmt.Println(filepath.Rel("C:/Users/abc/def", "C:/Users/abc"))8}

Full Screen

Full Screen

relPath

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Enter a string: ")4 fmt.Scanln(&str)5 for i := 0; i < len(str); i++ {6 fmt.Println(str[i])7 }8}9./main.go:9:2: non-bool str[i] (type byte) used as if condition10import "fmt"11func main() {12 fmt.Println("Enter a string: ")13 fmt.Scanln(&str)14 for i := 0; i < len(str); i++ {15 fmt.Println(str[i])16 }17}18./main.go:9:2: non-bool str[i] (type byte) used as if condition19import "fmt"20func main() {21 fmt.Println("Enter a string: ")22 fmt.Scanln(&str)23 for i := 0; i < len(str); i++ {24 fmt.Println(str[i])25 }26}27./main.go:9:2: non-bool str[i] (type byte) used as if condition28import "fmt"29func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful