func (t *DirTest) CloneToChildFile_DestinationExists() { const srcName = "blah/baz" dstName := path.Join(dirInodeName, "qux") var o *gcs.Object var err error // Create the source. src, err := gcsutil.CreateObject(t.ctx, t.bucket, srcName, []byte("taco")) AssertEq(nil, err) // And a destination object that will be overwritten. _, err = gcsutil.CreateObject(t.ctx, t.bucket, dstName, []byte("")) AssertEq(nil, err) // Call the inode. o, err = t.in.CloneToChildFile(t.ctx, path.Base(dstName), src) AssertEq(nil, err) AssertNe(nil, o) ExpectEq(dstName, o.Name) ExpectFalse(inode.IsSymlink(o)) ExpectEq(len("taco"), o.Size) // Check resulting contents. contents, err := gcsutil.ReadObject(t.ctx, t.bucket, dstName) AssertEq(nil, err) ExpectEq("taco", string(contents)) }
func (t *DirTest) CreateChildDir_DoesntExist() { const name = "qux" objName := path.Join(dirInodeName, name) + "/" var o *gcs.Object var err error // Call the inode. o, err = t.in.CreateChildDir(t.ctx, name) AssertEq(nil, err) AssertNe(nil, o) ExpectEq(objName, o.Name) ExpectFalse(inode.IsSymlink(o)) }
func (t *DirTest) CreateChildFile_DoesntExist() { const name = "qux" objName := path.Join(dirInodeName, name) var o *gcs.Object var err error // Call the inode. o, err = t.in.CreateChildFile(t.ctx, name) AssertEq(nil, err) AssertNe(nil, o) ExpectEq(objName, o.Name) ExpectFalse(inode.IsSymlink(o)) ExpectEq(1, len(o.Metadata)) ExpectEq( t.clock.Now().UTC().Format(time.RFC3339Nano), o.Metadata["gcsfuse_mtime"]) }
// Implementation detail of lookUpOrCreateInodeIfNotStale; do not use outside // of that function. // // LOCKS_REQUIRED(fs.mu) func (fs *fileSystem) mintInode(name string, o *gcs.Object) (in inode.Inode) { // Choose an ID. id := fs.nextInodeID fs.nextInodeID++ // Create the inode. switch { // Explicit directories case o != nil && inode.IsDirName(o.Name): in = inode.NewExplicitDirInode( id, o, fuseops.InodeAttributes{ Uid: fs.uid, Gid: fs.gid, Mode: fs.dirMode, }, fs.implicitDirs, fs.dirTypeCacheTTL, fs.bucket, fs.mtimeClock, fs.cacheClock) // Implicit directories case inode.IsDirName(name): in = inode.NewDirInode( id, name, fuseops.InodeAttributes{ Uid: fs.uid, Gid: fs.gid, Mode: fs.dirMode, }, fs.implicitDirs, fs.dirTypeCacheTTL, fs.bucket, fs.mtimeClock, fs.cacheClock) case inode.IsSymlink(o): in = inode.NewSymlinkInode( id, o, fuseops.InodeAttributes{ Uid: fs.uid, Gid: fs.gid, Mode: fs.fileMode | os.ModeSymlink, }) default: in = inode.NewFileInode( id, o, fuseops.InodeAttributes{ Uid: fs.uid, Gid: fs.gid, Mode: fs.fileMode, }, fs.bucket, fs.syncer, fs.tempDir, fs.mtimeClock) } // Place it in our map of IDs to inodes. fs.inodes[in.ID()] = in return }