2018-10-10 02:34:24 -07:00
|
|
|
// Copyright (C) 2018 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2019-11-29 01:11:52 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/db/backend"
|
2018-10-10 02:34:24 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lowlevel is the lowest level database interface. It has a very simple
|
2019-11-29 01:11:52 -07:00
|
|
|
// purpose: hold the actual backend database, and the in-memory state
|
2018-10-10 02:34:24 -07:00
|
|
|
// that belong to that database. In the same way that a single on disk
|
|
|
|
// database can only be opened once, there should be only one Lowlevel for
|
2019-11-29 01:11:52 -07:00
|
|
|
// any given backend.
|
2018-10-10 02:34:24 -07:00
|
|
|
type Lowlevel struct {
|
2019-11-29 01:11:52 -07:00
|
|
|
backend.Backend
|
2018-10-10 02:34:24 -07:00
|
|
|
folderIdx *smallIndex
|
|
|
|
deviceIdx *smallIndex
|
2019-08-20 00:41:41 -07:00
|
|
|
}
|
|
|
|
|
2018-10-10 02:34:24 -07:00
|
|
|
// NewLowlevel wraps the given *leveldb.DB into a *lowlevel
|
2019-11-29 01:11:52 -07:00
|
|
|
func NewLowlevel(db backend.Backend) *Lowlevel {
|
2018-10-10 02:34:24 -07:00
|
|
|
return &Lowlevel{
|
2019-11-29 01:11:52 -07:00
|
|
|
Backend: db,
|
2018-10-10 02:34:24 -07:00
|
|
|
folderIdx: newSmallIndex(db, []byte{KeyTypeFolderIdx}),
|
|
|
|
deviceIdx: newSmallIndex(db, []byte{KeyTypeDeviceIdx}),
|
2019-02-14 16:15:13 -07:00
|
|
|
}
|
|
|
|
}
|
2019-05-02 02:15:00 -07:00
|
|
|
|
2019-11-29 01:11:52 -07:00
|
|
|
// ListFolders returns the list of folders currently in the database
|
|
|
|
func (db *Lowlevel) ListFolders() []string {
|
|
|
|
return db.folderIdx.Values()
|
2019-07-26 13:18:42 -07:00
|
|
|
}
|