本文整理汇总了Golang中github.com/jacobsa/fuse/fuseops.CreateFileOp.Context方法的典型用法代码示例。如果您正苦于以下问题:Golang CreateFileOp.Context方法的具体用法?Golang CreateFileOp.Context怎么用?Golang CreateFileOp.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jacobsa/fuse/fuseops.CreateFileOp
的用法示例。
在下文中一共展示了CreateFileOp.Context方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateFile
// LOCKS_EXCLUDED(fs.mu)
func (fs *fileSystem) CreateFile(
op *fuseops.CreateFileOp) (err error) {
// Find the parent.
fs.mu.Lock()
parent := fs.inodes[op.Parent].(inode.DirInode)
fs.mu.Unlock()
// Create an empty backing object for the child, failing if it already
// exists.
parent.Lock()
o, err := parent.CreateChildFile(op.Context(), op.Name)
parent.Unlock()
// Special case: *gcs.PreconditionError means the name already exists.
if _, ok := err.(*gcs.PreconditionError); ok {
err = fuse.EEXIST
return
}
// Propagate other errors.
if err != nil {
err = fmt.Errorf("CreateChildFile: %v", err)
return
}
// Attempt to create a child inode using the object we created. If we fail to
// do so, it means someone beat us to the punch with a newer generation
// (unlikely, so we're probably okay with failing here).
fs.mu.Lock()
child := fs.lookUpOrCreateInodeIfNotStale(o.Name, o)
if child == nil {
err = fmt.Errorf("Newly-created record is already stale")
return
}
defer fs.unlockAndMaybeDisposeOfInode(child, &err)
// Fill out the response.
op.Entry.Child = child.ID()
op.Entry.Attributes, err = child.Attributes(op.Context())
if err != nil {
err = fmt.Errorf("Attributes: %v", err)
return
}
return
}