MCPcopy Create free account
hub / github.com/plexdrive/plexdrive / GetObjectByParentAndName

Method GetObjectByParentAndName

drive/cache.go:170–195  ·  view source on GitHub ↗

GetObjectByParentAndName finds a child element by name and its parent id

(parent, name string)

Source from the content-addressed store, hash-verified

168
169// GetObjectByParentAndName finds a child element by name and its parent id
170func (c *Cache) GetObjectByParentAndName(parent, name string) (object *APIObject, err error) {
171 Log.Tracef("Getting object %v in parent %v", name, parent)
172
173 c.db.View(func(tx *bolt.Tx) error {
174 // Look up object id in parent-name index
175 b := tx.Bucket(bParents)
176 v := b.Get([]byte(parent + "/" + name))
177 if nil == v {
178 return nil
179 }
180
181 // Fetch object for given id
182 object, err = boltGetObject(tx, string(v))
183 return nil
184 })
185 if nil != err {
186 return nil, err
187 }
188
189 if object == nil {
190 return nil, fmt.Errorf("Could not find object with name %v in parent %v", name, parent)
191 }
192
193 Log.Tracef("Got object from cache %v", object)
194 return object, nil
195}
196
197// DeleteObject deletes an object by id
198func (c *Cache) DeleteObject(id string) error {

Callers 3

LookupMethod · 0.45
RemoveMethod · 0.45
RenameMethod · 0.45

Calls 1

boltGetObjectFunction · 0.85

Tested by

no test coverage detected