MCPcopy Create free account
hub / github.com/blues/note / AddNotefile

Method AddNotefile

lib/notebox.go:834–874  ·  view source on GitHub ↗

AddNotefile adds a new notefile to the notebox, and return "nil" if it already exists

(ctx context.Context, notefileID string, notefileInfo *note.NotefileInfo)

Source from the content-addressed store, hash-verified

832
833// AddNotefile adds a new notefile to the notebox, and return "nil" if it already exists
834func (box *Notebox) AddNotefile(ctx context.Context, notefileID string, notefileInfo *note.NotefileInfo) error {
835 // First, do an immediate check to see if it already exists. If so, short circuit everything
836 // and return a clean "no error", which is relied upon by callers.
837 if box.NotefileExists(notefileID) {
838
839 // Refresh the notefile info, which may likely have changed
840 if notefileInfo == nil {
841 notefileInfo = &note.NotefileInfo{}
842 }
843
844 return box.SetNotefileInfo(ctx, notefileID, *notefileInfo)
845
846 }
847
848 // Find out if it's a queue
849 isQueue, _, _, _, _, err := NotefileAttributesFromID(notefileID)
850 if err != nil {
851 return err
852 }
853
854 // Add the notefile
855 box.Openfile().lock.Lock()
856 defer box.Openfile().lock.Unlock()
857
858 // Re-check existence while holding the lock to prevent race conditions
859 if box.NotefileExists(notefileID) {
860 // Refresh the notefile info, which may likely have changed
861 if notefileInfo == nil {
862 notefileInfo = &note.NotefileInfo{}
863 }
864 return box.SetNotefileInfo(ctx, notefileID, *notefileInfo)
865 }
866
867 boxfile := box.Notefile()
868 boxfile.lock.Lock()
869 err = box.uAddNotefile(ctx, notefileID, notefileInfo, CreateNotefile(isQueue))
870 boxfile.lock.Unlock()
871
872 // Done
873 return err
874}
875
876// GetNotefileInfo retrieves info about a specific notefile
877func (box *Notebox) GetNotefileInfo(notefileID string) (notefileInfo note.NotefileInfo, err error) {

Callers 12

RequestMethod · 0.95
TestNoteboxExtremeRaceFunction · 0.80
hubNotefileAddNoteFunction · 0.80
TestNoteboxExtendedRaceFunction · 0.80
TestNoteboxTortureFunction · 0.80
testNoteboxFunction · 0.80

Calls 7

NotefileExistsMethod · 0.95
SetNotefileInfoMethod · 0.95
OpenfileMethod · 0.95
NotefileMethod · 0.95
uAddNotefileMethod · 0.95
NotefileAttributesFromIDFunction · 0.85
CreateNotefileFunction · 0.85