40
40
package directory
41
41
42
42
import (
43
+ "context"
43
44
"errors"
44
45
45
46
"github.com/apple/foundationdb/bindings/go/src/fdb"
@@ -79,7 +80,7 @@ type Directory interface {
79
80
// recorded as the layer; if layer is specified and the directory already
80
81
// exists, it is compared against the layer specified when the directory was
81
82
// created, and an error is returned if they differ.
82
- CreateOrOpen (t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error )
83
+ CreateOrOpen (ctx context. Context , t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error )
83
84
84
85
// Open opens the directory specified by path (relative to this Directory),
85
86
// and returns the directory and its contents as a DirectorySubspace (or ErrDirNotExists
@@ -89,15 +90,15 @@ type Directory interface {
89
90
// If the byte slice layer is specified, it is compared against the layer
90
91
// specified when the directory was created, and an error is returned if
91
92
// they differ.
92
- Open (rt fdb.ReadTransactor , path []string , layer []byte ) (DirectorySubspace , error )
93
+ Open (ctx context. Context , rt fdb.ReadTransactor , path []string , layer []byte ) (DirectorySubspace , error )
93
94
94
95
// Create creates a directory specified by path (relative to this
95
96
// Directory), and returns the directory and its contents as a
96
97
// DirectorySubspace (or ErrDirAlreadyExists if the directory already exists).
97
98
//
98
99
// If the byte slice layer is specified, it is recorded as the layer and
99
100
// will be checked when opening the directory in the future.
100
- Create (t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error )
101
+ Create (ctx context. Context , t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error )
101
102
102
103
// CreatePrefix behaves like Create, but uses a manually specified byte
103
104
// slice prefix to physically store the contents of this directory, rather
@@ -106,7 +107,7 @@ type Directory interface {
106
107
// If this Directory was created in a root directory that does not allow
107
108
// manual prefixes, CreatePrefix will return an error. The default root
108
109
// directory does not allow manual prefixes.
109
- CreatePrefix (t fdb.Transactor , path []string , layer []byte , prefix []byte ) (DirectorySubspace , error )
110
+ CreatePrefix (ctx context. Context , t fdb.Transactor , path []string , layer []byte , prefix []byte ) (DirectorySubspace , error )
110
111
111
112
// Move moves the directory at oldPath to newPath (both relative to this
112
113
// Directory), and returns the directory (at its new location) and its
@@ -116,7 +117,7 @@ type Directory interface {
116
117
//
117
118
// There is no effect on the physical prefix of the given directory or on
118
119
// clients that already have the directory open.
119
- Move (t fdb.Transactor , oldPath []string , newPath []string ) (DirectorySubspace , error )
120
+ Move (ctx context. Context , t fdb.Transactor , oldPath []string , newPath []string ) (DirectorySubspace , error )
120
121
121
122
// MoveTo moves this directory to newAbsolutePath (relative to the root
122
123
// directory of this Directory), and returns the directory (at its new
@@ -126,7 +127,7 @@ type Directory interface {
126
127
//
127
128
// There is no effect on the physical prefix of the given directory or on
128
129
// clients that already have the directory open.
129
- MoveTo (t fdb.Transactor , newAbsolutePath []string ) (DirectorySubspace , error )
130
+ MoveTo (ctx context. Context , t fdb.Transactor , newAbsolutePath []string ) (DirectorySubspace , error )
130
131
131
132
// Remove removes the directory at path (relative to this Directory), its
132
133
// content, and all subdirectories. Remove returns true if a directory
@@ -135,16 +136,16 @@ type Directory interface {
135
136
//
136
137
// Note that clients that have already opened this directory might still
137
138
// insert data into its contents after removal.
138
- Remove (t fdb.Transactor , path []string ) (bool , error )
139
+ Remove (ctx context. Context , t fdb.Transactor , path []string ) (bool , error )
139
140
140
141
// Exists returns true if the directory at path (relative to this Directory)
141
142
// exists, and false otherwise.
142
- Exists (rt fdb.ReadTransactor , path []string ) (bool , error )
143
+ Exists (ctx context. Context , rt fdb.ReadTransactor , path []string ) (bool , error )
143
144
144
145
// List returns the names of the immediate subdirectories of the directory
145
146
// at path (relative to this Directory) as a slice of strings. Each string
146
147
// is the name of the last component of a subdirectory's path.
147
- List (rt fdb.ReadTransactor , path []string ) ([]string , error )
148
+ List (ctx context. Context , rt fdb.ReadTransactor , path []string ) ([]string , error )
148
149
149
150
// GetLayer returns the layer specified when this Directory was created.
150
151
GetLayer () []byte
@@ -165,14 +166,14 @@ func stringsEqual(a, b []string) bool {
165
166
return true
166
167
}
167
168
168
- func moveTo (t fdb.Transactor , dl directoryLayer , path , newAbsolutePath []string ) (DirectorySubspace , error ) {
169
+ func moveTo (ctx context. Context , t fdb.Transactor , dl directoryLayer , path , newAbsolutePath []string ) (DirectorySubspace , error ) {
169
170
partition_len := len (dl .path )
170
171
171
172
if ! stringsEqual (newAbsolutePath [:partition_len ], dl .path ) {
172
173
return nil , errors .New ("cannot move between partitions" )
173
174
}
174
175
175
- return dl .Move (t , path [partition_len :], newAbsolutePath [partition_len :])
176
+ return dl .Move (ctx , t , path [partition_len :], newAbsolutePath [partition_len :])
176
177
}
177
178
178
179
var root = NewDirectoryLayer (subspace .FromBytes ([]byte {0xFE }), subspace .AllKeys (), false )
@@ -186,8 +187,8 @@ var root = NewDirectoryLayer(subspace.FromBytes([]byte{0xFE}), subspace.AllKeys(
186
187
// as the layer; if layer is specified and the directory already exists, it is
187
188
// compared against the layer specified when the directory was created, and an
188
189
// error is returned if they differ.
189
- func CreateOrOpen (t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error ) {
190
- return root .CreateOrOpen (t , path , layer )
190
+ func CreateOrOpen (ctx context. Context , t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error ) {
191
+ return root .CreateOrOpen (ctx , t , path , layer )
191
192
}
192
193
193
194
// Open opens the directory specified by path (resolved relative to the default
@@ -197,8 +198,8 @@ func CreateOrOpen(t fdb.Transactor, path []string, layer []byte) (DirectorySubsp
197
198
// If the byte slice layer is specified, it is compared against the layer
198
199
// specified when the directory was created, and an error is returned if they
199
200
// differ.
200
- func Open (rt fdb.ReadTransactor , path []string , layer []byte ) (DirectorySubspace , error ) {
201
- return root .Open (rt , path , layer )
201
+ func Open (ctx context. Context , rt fdb.ReadTransactor , path []string , layer []byte ) (DirectorySubspace , error ) {
202
+ return root .Open (ctx , rt , path , layer )
202
203
}
203
204
204
205
// Create creates a directory specified by path (resolved relative to the
@@ -207,8 +208,8 @@ func Open(rt fdb.ReadTransactor, path []string, layer []byte) (DirectorySubspace
207
208
//
208
209
// If the byte slice layer is specified, it is recorded as the layer and will be
209
210
// checked when opening the directory in the future.
210
- func Create (t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error ) {
211
- return root .Create (t , path , layer )
211
+ func Create (ctx context. Context , t fdb.Transactor , path []string , layer []byte ) (DirectorySubspace , error ) {
212
+ return root .Create (ctx , t , path , layer )
212
213
}
213
214
214
215
// Move moves the directory at oldPath to newPath (both resolved relative to the
@@ -219,21 +220,21 @@ func Create(t fdb.Transactor, path []string, layer []byte) (DirectorySubspace, e
219
220
//
220
221
// There is no effect on the physical prefix of the given directory or on
221
222
// clients that already have the directory open.
222
- func Move (t fdb.Transactor , oldPath []string , newPath []string ) (DirectorySubspace , error ) {
223
- return root .Move (t , oldPath , newPath )
223
+ func Move (ctx context. Context , t fdb.Transactor , oldPath []string , newPath []string ) (DirectorySubspace , error ) {
224
+ return root .Move (ctx , t , oldPath , newPath )
224
225
}
225
226
226
227
// Exists returns true if the directory at path (relative to the default root
227
228
// directory) exists, and false otherwise.
228
- func Exists (rt fdb.ReadTransactor , path []string ) (bool , error ) {
229
- return root .Exists (rt , path )
229
+ func Exists (ctx context. Context , rt fdb.ReadTransactor , path []string ) (bool , error ) {
230
+ return root .Exists (ctx , rt , path )
230
231
}
231
232
232
233
// List returns the names of the immediate subdirectories of the default root
233
234
// directory as a slice of strings. Each string is the name of the last
234
235
// component of a subdirectory's path.
235
- func List (rt fdb.ReadTransactor , path []string ) ([]string , error ) {
236
- return root .List (rt , path )
236
+ func List (ctx context. Context , rt fdb.ReadTransactor , path []string ) ([]string , error ) {
237
+ return root .List (ctx , rt , path )
237
238
}
238
239
239
240
// Root returns the default root directory. Any attempt to move or remove the
0 commit comments