2018-10-10 09:34:24 +00: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 08:11:52 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/db/backend"
|
2018-10-10 09:34:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lowlevel is the lowest level database interface. It has a very simple
|
2019-11-29 08:11:52 +00:00
|
|
|
// purpose: hold the actual backend database, and the in-memory state
|
2018-10-10 09:34:24 +00: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 08:11:52 +00:00
|
|
|
// any given backend.
|
2018-10-10 09:34:24 +00:00
|
|
|
type Lowlevel struct {
|
2019-11-29 08:11:52 +00:00
|
|
|
backend.Backend
|
2018-10-10 09:34:24 +00:00
|
|
|
folderIdx *smallIndex
|
|
|
|
deviceIdx *smallIndex
|
2019-08-20 07:41:41 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:34:24 +00:00
|
|
|
// NewLowlevel wraps the given *leveldb.DB into a *lowlevel
|
2019-11-29 08:11:52 +00:00
|
|
|
func NewLowlevel(db backend.Backend) *Lowlevel {
|
2018-10-10 09:34:24 +00:00
|
|
|
return &Lowlevel{
|
2019-11-29 08:11:52 +00:00
|
|
|
Backend: db,
|
2018-10-10 09:34:24 +00:00
|
|
|
folderIdx: newSmallIndex(db, []byte{KeyTypeFolderIdx}),
|
|
|
|
deviceIdx: newSmallIndex(db, []byte{KeyTypeDeviceIdx}),
|
2019-02-14 23:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-02 09:15:00 +00:00
|
|
|
|
2019-11-29 08:11:52 +00:00
|
|
|
// ListFolders returns the list of folders currently in the database
|
|
|
|
func (db *Lowlevel) ListFolders() []string {
|
|
|
|
return db.folderIdx.Values()
|
2019-07-26 20:18:42 +00:00
|
|
|
}
|