Beispiel #1
0
// IMPORTANT: remember to close the database after usuage.
func openPageDatabase(pageName, pageDirectory string) (*bolt.DB, error) {
	CreateDefaultBuckets := func(PageDB *bolt.DB) error {
		UpdateFuncErr := PageDB.Update(func(tx *bolt.Tx) error {
			_, err := tx.CreateBucketIfNotExists([]byte("PageAttributes"))
			if err != nil {
				return err
			}
			return nil
		})
		return UpdateFuncErr
	}

	pageNameMod := malkovich.DocNameToFolderName(pageName)
	fn := filepath.Join(pageDirectory, pageNameMod) + ".db"
	db, err := bolt.Open(fn, 0600, nil)
	if err != nil {
		db.Close()
		return nil, err
	} else {
		err = CreateDefaultBuckets(db)
		if err != nil {
			db.Close()
			return nil, err
		} else {
			return db, nil
		}
	}
}
Beispiel #2
0
func getDocDirectory(DocRoot, DocName string) string {
	// TODO:HIGH probably need to do some validation of the doc name.
	DocFolderName := malkovich.DocNameToFolderName(DocName)
	fp := path.Join(DocRoot, "pages", DocFolderName)
	fp = filepath.ToSlash(fp)
	fp = path.Clean(fp)
	fp = filepath.FromSlash(fp)
	return fp
}
Beispiel #3
0
func getDocPreviewFilePath(DocRoot, DocName string) string {
	// TODO:HIGH probably need to do some validation of the doc name.
	DocFolderName := malkovich.DocNameToFolderName(DocName)
	fp := path.Join(DocRoot, "pages", DocFolderName, "page_summary.json")
	fp = filepath.ToSlash(fp)
	fp = path.Clean(fp)
	fp = filepath.FromSlash(fp)
	//TODO:HIGH ensure the file is contained under the DocRoot.
	return fp
}