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

Function NotefileAttributesFromID

lib/notebox.go:756–811  ·  view source on GitHub ↗

NotefileAttributesFromID extracts attributes implied by the notefileID

(notefileID string)

Source from the content-addressed store, hash-verified

754
755// NotefileAttributesFromID extracts attributes implied by the notefileID
756func NotefileAttributesFromID(notefileID string) (isQueue bool, syncToHub bool, syncFromHub bool, secure bool, reserved bool, err error) {
757 // See if it's a reserved filename
758 reserved = strings.HasPrefix(notefileID, "_")
759
760 // Look at the extension
761 components := strings.Split(notefileID, ".")
762 numComponents := len(components)
763 if numComponents < 2 {
764 err = fmt.Errorf("notefileID must end in a recognized type: %s "+note.ErrNotefileName, notefileID)
765 return
766 }
767 notefileType := components[numComponents-1]
768 extension := notefileType
769
770 // First, look for the base type
771 validType := false
772 if strings.HasPrefix(notefileType, "q") {
773 notefileType = strings.TrimPrefix(notefileType, "q")
774 isQueue = true
775 syncToHub = true
776 syncFromHub = true
777 validType = true
778 } else if strings.HasPrefix(notefileType, "db") {
779 notefileType = strings.TrimPrefix(notefileType, "db")
780 syncToHub = true
781 syncFromHub = true
782 validType = true
783 }
784
785 // Now, look for I/O attributes
786 if strings.HasPrefix(notefileType, "i") {
787 notefileType = strings.TrimPrefix(notefileType, "i")
788 syncToHub = false
789 } else if strings.HasPrefix(notefileType, "o") {
790 notefileType = strings.TrimPrefix(notefileType, "o")
791 syncFromHub = false
792 } else if strings.HasPrefix(notefileType, "x") {
793 notefileType = strings.TrimPrefix(notefileType, "x")
794 syncFromHub = false
795 syncToHub = false
796 }
797
798 // Now, look for the security attribute
799 if strings.HasPrefix(notefileType, "s") {
800 notefileType = strings.TrimPrefix(notefileType, "s")
801 secure = true
802 }
803
804 // If we haven't gotten a type or exhausted the option flags, it's unrecognized
805 if !validType || notefileType != "" {
806 err = fmt.Errorf("notefile type not recognized: %s "+note.ErrNotefileName, extension)
807 }
808
809 // Done
810 return
811}
812
813// NotefileExists returns true if notefile exists and is not deleted

Callers 7

RequestMethod · 0.85
GetChangedNotefilesMethod · 0.85
AddNotefileMethod · 0.85
uAddNotefileMethod · 0.85
OpenNotefileMethod · 0.85
hubNoteboxSummaryFunction · 0.85
hubNotefileAddNoteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected