本文整理匯總了Golang中github.com/gholt/store.IsNotFound函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsNotFound函數的具體用法?Golang IsNotFound怎麽用?Golang IsNotFound使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsNotFound函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RevokeAddrFS
// RevokeAddrFS ...
func (s *FileSystemAPIServer) RevokeAddrFS(ctx context.Context, r *pb.RevokeAddrFSRequest) (*pb.RevokeAddrFSResponse, error) {
var err error
var acctID string
var value []byte
var fsRef FileSysRef
srcAddr := ""
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
srcAddr = pr.Addr.String()
}
// Validate Token
acctID, err = s.validateToken(r.Token)
if err != nil {
log.Printf("%s REVOKE FAILED %s\n", srcAddr, "PermissionDenied")
return nil, errf(codes.PermissionDenied, "%v", "Invalid Token")
}
// Validate Token/Account owns this file system
// Read FileSysRef entry to determine if it exists
pKey := fmt.Sprintf("/fs")
pKeyA, pKeyB := murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB := murmur3.Sum128([]byte(r.FSid))
_, value, err = s.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
log.Printf("%s REVOKE FAILED %s NOTFOUND", srcAddr, r.FSid)
return nil, errf(codes.NotFound, "%v", "Not Found")
}
if err != nil {
log.Printf("%s REVOKE FAILED %v\n", srcAddr, err)
return nil, errf(codes.Internal, "%v", err)
}
err = json.Unmarshal(value, &fsRef)
if err != nil {
log.Printf("%s REVOKE FAILED %v\n", srcAddr, err)
return nil, errf(codes.Internal, "%v", err)
}
if fsRef.AcctID != acctID {
log.Printf("$s REVOKE FAILED %v ACCOUNT MISMATCH", r.FSid)
return nil, errf(codes.FailedPrecondition, "%v", "Account Mismatch")
}
// REVOKE an file system entry for the addr
// delete /fs/FSID/addr addr AddrRef
pKey = fmt.Sprintf("/fs/%s/addr", r.FSid)
pKeyA, pKeyB = murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB = murmur3.Sum128([]byte(r.Addr))
timestampMicro := brimtime.TimeToUnixMicro(time.Now())
_, err = s.gstore.Delete(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, timestampMicro)
if store.IsNotFound(err) {
log.Printf("%s REVOKE FAILED %s %s\n", srcAddr, r.FSid, r.Addr)
return nil, errf(codes.NotFound, "%v", "Not Found")
}
// return Addr was revoked
// Log Operation
log.Printf("%s REVOKE SUCCESS %s %s\n", srcAddr, r.FSid, r.Addr)
return &pb.RevokeAddrFSResponse{Data: r.FSid}, nil
}
示例2: run
func (d *Deletinator) run() {
// TODO: Parallelize this thing?
for {
todelete := <-d.in
log.Println("Deleting: ", todelete)
// TODO: Need better context
p := &peer.Peer{
Addr: localAddr{},
}
ctx := peer.NewContext(context.Background(), p)
// Get the dir entry info
dirent, err := d.fs.GetDirent(ctx, todelete.parent, todelete.name)
if store.IsNotFound(err) {
// NOTE: If it isn't found then it is likely deleted.
// Do we need to do more to ensure this?
// Skip for now
continue
}
if err != nil {
// TODO Better error handling?
// re-q the id, to try again later
log.Print("Delete error getting dirent: ", err)
d.in <- todelete
continue
}
ts := dirent.Tombstone
deleted := uint64(0)
for b := uint64(0); b < ts.Blocks; b++ {
log.Println(" Deleting block: ", b)
// Delete each block
id := GetID(ts.FsId, ts.Inode, b+1)
err := d.fs.DeleteChunk(ctx, id, ts.Dtime)
if err != nil && !store.IsNotFound(err) && err != ErrStoreHasNewerValue {
continue
}
deleted++
}
if deleted == ts.Blocks {
// Everything is deleted so delete the entry
log.Println(" Deleting Inode")
err := d.fs.DeleteChunk(ctx, GetID(ts.FsId, ts.Inode, 0), ts.Dtime)
if err != nil && !store.IsNotFound(err) && err != ErrStoreHasNewerValue {
// Couldn't delete the inode entry so try again later
d.in <- todelete
continue
}
log.Println(" Deleting Listing")
err = d.fs.DeleteListing(ctx, todelete.parent, todelete.name, ts.Dtime)
if err != nil && !store.IsNotFound(err) && err != ErrStoreHasNewerValue {
log.Println(" Err: ", err)
// TODO: Better error handling
// Ignore for now to be picked up later?
}
} else {
// If all artifacts are not deleted requeue for later
d.in <- todelete
}
}
}
示例3: Lookup
func (o *OortFS) Lookup(ctx context.Context, parent []byte, name string) (string, *pb.Attr, error) {
// Get the id
b, err := o.comms.ReadGroupItem(ctx, parent, []byte(name))
if store.IsNotFound(err) {
return "", &pb.Attr{}, nil
} else if err != nil {
return "", &pb.Attr{}, err
}
d := &pb.DirEntry{}
err = proto.Unmarshal(b, d)
if err != nil {
return "", &pb.Attr{}, err
}
if d.Tombstone != nil {
return "", &pb.Attr{}, nil
}
// Get the Inode entry
b, err = o.GetChunk(ctx, d.Id)
if err != nil {
return "", &pb.Attr{}, err
}
n := &pb.InodeEntry{}
err = proto.Unmarshal(b, n)
if err != nil {
return "", &pb.Attr{}, err
}
return d.Name, n.Attr, nil
}
示例4: RevokeAddrFS
// RevokeAddrFS ...
func (s *FileSystemAPIServer) RevokeAddrFS(ctx context.Context, r *pb.RevokeAddrFSRequest) (*pb.RevokeAddrFSResponse, error) {
var err error
srcAddr := ""
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
srcAddr = pr.Addr.String()
}
// Validate Token
_, err = s.validateToken(r.Token)
if err != nil {
log.Printf("%s REVOKE FAILED %s\n", srcAddr, "PermissionDenied")
return nil, errf(codes.PermissionDenied, "%v", "Invalid Token")
}
// REVOKE an file system entry for the addr
// delete /fs/FSID/addr addr AddrRef
pKey := fmt.Sprintf("/fs/%s/addr", r.FSid)
pKeyA, pKeyB := murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB := murmur3.Sum128([]byte(r.Addr))
timestampMicro := brimtime.TimeToUnixMicro(time.Now())
_, err = s.gstore.Delete(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, timestampMicro)
if store.IsNotFound(err) {
log.Printf("%s REVOKE FAILED %s %s\n", srcAddr, r.FSid, r.Addr)
return nil, errf(codes.NotFound, "%v", "Not Found")
}
// return Addr was revoked
// Log Operation
log.Printf("%s REVOKE SUCCESS %s %s\n", srcAddr, r.FSid, r.Addr)
return &pb.RevokeAddrFSResponse{Data: r.FSid}, nil
}
示例5: Rename
func (o *OortFS) Rename(ctx context.Context, oldParent, newParent []byte, oldName, newName string) (*pb.RenameResponse, error) {
// Get the ID from the group list
b, err := o.comms.ReadGroupItem(ctx, oldParent, []byte(oldName))
if store.IsNotFound(err) {
return &pb.RenameResponse{}, nil
}
if err != nil {
return &pb.RenameResponse{}, err
}
d := &pb.DirEntry{}
err = proto.Unmarshal(b, d)
if err != nil {
return &pb.RenameResponse{}, err
}
// TODO: Handle orphaned data from overwrites
// Create new entry
d.Name = newName
b, err = proto.Marshal(d)
err = o.comms.WriteGroup(ctx, newParent, []byte(newName), b)
if err != nil {
return &pb.RenameResponse{}, err
}
// Delete old entry
err = o.comms.DeleteGroupItem(ctx, oldParent, []byte(oldName))
if err != nil {
// TODO: Handle errors
// If we fail here then we will have two entries
return &pb.RenameResponse{}, err
}
return &pb.RenameResponse{}, nil
}
示例6: TranslateError
func TranslateError(err error) string {
if store.IsDisabled(err) {
return "::github.com/gholt/store/ErrDisabled::"
} else if store.IsNotFound(err) {
return "::github.com/gholt/store/ErrNotFound::"
}
return err.Error()
}
示例7: Create
func (o *OortFS) Create(ctx context.Context, parent, id []byte, inode uint64, name string, attr *pb.Attr, isdir bool) (string, *pb.Attr, error) {
// Check to see if the name already exists
b, err := o.comms.ReadGroupItem(ctx, parent, []byte(name))
if err != nil && !store.IsNotFound(err) {
// TODO: Needs beter error handling
return "", &pb.Attr{}, err
}
if len(b) > 0 {
p := &pb.DirEntry{}
err = formic.Unmarshal(b, p)
if err != nil {
return "", &pb.Attr{}, err
}
// Return an error if entry already exists and is not a tombstone
if p.Tombstone == nil {
return "", &pb.Attr{}, nil
}
}
var direntType fuse.DirentType
if isdir {
direntType = fuse.DT_Dir
} else {
direntType = fuse.DT_File
}
// Add the name to the group
d := &pb.DirEntry{
Version: DirEntryVersion,
Name: name,
Id: id,
Type: uint32(direntType),
}
b, err = formic.Marshal(d)
if err != nil {
return "", &pb.Attr{}, err
}
err = o.comms.WriteGroup(ctx, parent, []byte(name), b)
if err != nil {
return "", &pb.Attr{}, err
}
// Add the inode entry
n := &pb.InodeEntry{
Version: InodeEntryVersion,
Inode: inode,
IsDir: isdir,
Attr: attr,
Blocks: 0,
}
b, err = formic.Marshal(n)
if err != nil {
return "", &pb.Attr{}, err
}
err = o.WriteChunk(ctx, id, b)
if err != nil {
return "", &pb.Attr{}, err
}
return name, attr, nil
}
示例8: validateToken
// validateToken ...
func (s *FileSystemAPIServer) validateToken(t string) (string, error) {
var tData TokenRef
var aData AcctPayLoad
var tDataByte []byte
var aDataByte []byte
var err error
// Read Token
pKeyA, pKeyB := murmur3.Sum128([]byte("/token"))
cKeyA, cKeyB := murmur3.Sum128([]byte(t))
_, tDataByte, err = s.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
return "", errors.New("Not Found")
}
err = json.Unmarshal(tDataByte, &tData)
if err != nil {
log.Printf("TOKEN FAILED %v\n", err)
return "", err
}
// Read Account
pKeyA, pKeyB = murmur3.Sum128([]byte("/acct"))
cKeyA, cKeyB = murmur3.Sum128([]byte(tData.AcctID))
_, aDataByte, err = s.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
return "", errors.New("Not Found")
}
err = json.Unmarshal(aDataByte, &aData)
if err != nil {
log.Printf("TOKEN FAILED %v\n", err)
return "", err
}
if tData.TokenID != aData.Token {
// Log Failed Operation
log.Printf("TOKEN FAIL %s\n", t)
return "", errors.New("Invalid Token")
}
// Return Account UUID
// Log Operation
log.Printf("TOKEN SUCCESS %s\n", tData.AcctID)
return tData.AcctID, nil
}
示例9: Create
func (o *OortFS) Create(ctx context.Context, parent, id []byte, inode uint64, name string, attr *pb.Attr, isdir bool) (string, *pb.Attr, error) {
v, err := o.validateIP(ctx)
if err != nil {
return "", nil, err
}
if !v {
return "", nil, errors.New("Unknown or unauthorized FS use")
}
// Check to see if the name already exists
b, err := o.comms.ReadGroupItem(ctx, parent, []byte(name))
if err != nil && !store.IsNotFound(err) {
// TODO: Needs beter error handling
return "", &pb.Attr{}, err
}
if len(b) > 0 {
return "", &pb.Attr{}, nil
}
p := &pb.DirEntry{}
err = proto.Unmarshal(b, p)
if err != nil {
return "", &pb.Attr{}, err
}
// Add the name to the group
d := &pb.DirEntry{
Version: DirEntryVersion,
Name: name,
Id: id,
}
b, err = proto.Marshal(d)
if err != nil {
return "", &pb.Attr{}, err
}
err = o.comms.WriteGroup(ctx, parent, []byte(name), b)
if err != nil {
return "", &pb.Attr{}, err
}
// Add the inode entry
n := &pb.InodeEntry{
Version: InodeEntryVersion,
Inode: inode,
IsDir: isdir,
Attr: attr,
Blocks: 0,
}
b, err = proto.Marshal(n)
if err != nil {
return "", &pb.Attr{}, err
}
err = o.WriteChunk(ctx, id, b)
if err != nil {
return "", &pb.Attr{}, err
}
return name, attr, nil
}
示例10: ShowFS
// ShowFS ...
func (s *FileSystemAPIServer) ShowFS(ctx context.Context, r *fb.ShowFSRequest) (*fb.ShowFSResponse, error) {
var status string
var acctData AcctPayLoad
var fsData FileSysPayLoad
var fsDataB []byte
var err error
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
fmt.Println(pr.Addr)
}
// getAcct data
acctData, err = s.getAcct("/acct", r.Acctnum)
if err != nil {
log.Printf("Error %v on lookup for account %s", err, r.Acctnum)
return nil, err
}
// validate token
if acctData.Token != r.Token {
return nil, errf(codes.PermissionDenied, "%s", "Invalid Token")
}
pKey := fmt.Sprintf("/acct/%s/fs", r.Acctnum)
pKeyA, pKeyB := murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB := murmur3.Sum128([]byte(r.FSid))
_, fsDataB, err = s.fsws.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
return nil, errf(codes.NotFound, "%v", "File System Not Found")
}
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
err = json.Unmarshal(fsDataB, &fsData)
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
// Get list of Addr
fsData.Addr, err = s.addrList(fsData.ID)
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
fsDataB, err = json.Marshal(&fsData)
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
// Prep things to return
status = "OK"
return &fb.ShowFSResponse{Payload: string(fsDataB), Status: status}, nil
}
示例11: getGStore
// lookupAccount ...
func (fsws *FileSystemWS) getGStore(g string, m string) (string, error) {
log.Println("Starting a Read from the Group Store")
keyA, keyB := murmur3.Sum128([]byte(g))
childKeyA, childKeyB := murmur3.Sum128([]byte(m))
_, value, err := fsws.gstore.Read(context.Background(), keyA, keyB, childKeyA, childKeyB, nil)
if store.IsNotFound(err) {
log.Printf(" Not Found Key: %d, %d ChildKey: %d, %d", keyA, keyB, childKeyA, childKeyB)
return "", nil
} else if err != nil {
return "", err
}
log.Println("Successfully read an item from the Group Store")
return fmt.Sprintf("%s", value), nil
}
示例12: Remove
func (o *OortFS) Remove(ctx context.Context, parent []byte, name string) (int32, error) {
v, err := o.validateIP(ctx)
if err != nil {
return 1, err
}
if !v {
return 1, errors.New("Unknown or unauthorized FS use")
}
// Get the ID from the group list
b, err := o.comms.ReadGroupItem(ctx, parent, []byte(name))
if store.IsNotFound(err) {
return 1, nil
} else if err != nil {
return 1, err
}
d := &pb.DirEntry{}
err = proto.Unmarshal(b, d)
if err != nil {
return 1, err
}
// TODO: More error handling needed
// TODO: Handle possible race conditions where user writes and deletes the same file over and over
// Mark the item deleted in the group
t := &pb.Tombstone{}
tsm := brimtime.TimeToUnixMicro(time.Now())
t.Dtime = tsm
t.Qtime = tsm
t.FsId = []byte("1") // TODO: Make sure this gets set when we are tracking fsids
inode, err := o.GetInode(ctx, d.Id)
if err != nil {
return 1, err
}
t.Blocks = inode.Blocks
t.Inode = inode.Inode
d.Tombstone = t
b, err = proto.Marshal(d)
if err != nil {
return 1, err
}
// NOTE: The tsm-1 is kind of a hack because the timestamp needs to be updated on this write, but if we choose tsm, once the actual delete comes through, it will not work because it is going to try to delete with a timestamp of tsm.
err = o.comms.WriteGroupTS(ctx, parent, []byte(name), b, tsm-1)
if err != nil {
return 1, err // Not really sure what should be done here to try to recover from err
}
o.deleteChan <- &DeleteItem{
parent: parent,
name: name,
}
return 0, nil
}
示例13: Symlink
func (o *OortFS) Symlink(ctx context.Context, parent, id []byte, name string, target string, attr *pb.Attr, inode uint64) (*pb.SymlinkResponse, error) {
v, err := o.validateIP(ctx)
if err != nil {
return nil, err
}
if !v {
return nil, errors.New("Unknown or unauthorized FS use")
}
// Check to see if the name exists
val, err := o.comms.ReadGroupItem(ctx, parent, []byte(name))
if err != nil && !store.IsNotFound(err) {
// TODO: Needs beter error handling
return &pb.SymlinkResponse{}, err
}
if len(val) > 1 { // Exists already
return &pb.SymlinkResponse{}, nil
}
n := &pb.InodeEntry{
Version: InodeEntryVersion,
Inode: inode,
IsDir: false,
IsLink: true,
Target: target,
Attr: attr,
}
b, err := proto.Marshal(n)
if err != nil {
return &pb.SymlinkResponse{}, err
}
err = o.WriteChunk(ctx, id, b)
if err != nil {
return &pb.SymlinkResponse{}, err
}
// Add the name to the group
d := &pb.DirEntry{
Version: DirEntryVersion,
Name: name,
Id: id,
}
b, err = proto.Marshal(d)
if err != nil {
return &pb.SymlinkResponse{}, err
}
err = o.comms.WriteGroup(ctx, parent, []byte(name), b)
if err != nil {
return &pb.SymlinkResponse{}, err
}
return &pb.SymlinkResponse{Name: name, Attr: attr}, nil
}
示例14: GetDirent
func (o *OortFS) GetDirent(ctx context.Context, parent []byte, name string) (*pb.DirEntry, error) {
// Get the Dir Entry
b, err := o.comms.ReadGroupItem(ctx, parent, []byte(name))
if store.IsNotFound(err) {
return &pb.DirEntry{}, nil
} else if err != nil {
return &pb.DirEntry{}, err
}
d := &pb.DirEntry{}
err = proto.Unmarshal(b, d)
if err != nil {
return &pb.DirEntry{}, err
}
return d, nil
}
示例15: GetChunk
func (o *OortFS) GetChunk(ctx context.Context, id []byte) ([]byte, error) {
b, err := o.comms.ReadValue(ctx, id)
if store.IsNotFound(err) {
return nil, ErrNotFound
}
if err != nil {
return nil, err
}
fb := &pb.FileBlock{}
err = proto.Unmarshal(b, fb)
if err != nil {
return nil, err
}
// TODO: Validate checksum and handle errors
return fb.Data, nil
}