Debian Codegraph @

lib/notmuch/directory.go

raw
1 //go:build notmuch
2 // +build notmuch
3
4 package notmuch
5
6 /*
7 #cgo LDFLAGS: -lnotmuch
8
9 #include <notmuch.h>
10
11 */
12 import "C"
13 import "time"
14
15 type Directory struct {
16 dir *C.notmuch_directory_t
17 }
18
19 func (dir *Directory) SetModifiedTime(t time.Time) error {
20 cTime := C.time_t(t.Unix())
21 return errorWrap(C.notmuch_directory_set_mtime(dir.dir, cTime))
22 }
23
24 func (dir *Directory) ModifiedTime() time.Time {
25 cTime := C.notmuch_directory_get_mtime(dir.dir)
26 return time.Unix(int64(cTime), 0)
27 }
28
29 func (dir *Directory) Filenames() []string {
30 cFilenames := C.notmuch_directory_get_child_files(dir.dir)
31 defer C.notmuch_filenames_destroy(cFilenames)
32
33 filenames := []string{}
34 for C.notmuch_filenames_valid(cFilenames) > 0 {
35 filename := C.notmuch_filenames_get(cFilenames)
36 filenames = append(filenames, C.GoString(filename))
37 C.notmuch_filenames_move_to_next(cFilenames)
38 }
39 return filenames
40 }
41
42 func (dir *Directory) Directories() []string {
43 cFilenames := C.notmuch_directory_get_child_directories(dir.dir)
44 defer C.notmuch_filenames_destroy(cFilenames)
45
46 filenames := []string{}
47 for C.notmuch_filenames_valid(cFilenames) > 0 {
48 filename := C.notmuch_filenames_get(cFilenames)
49 filenames = append(filenames, C.GoString(filename))
50 C.notmuch_filenames_move_to_next(cFilenames)
51 }
52 return filenames
53 }
54
55 // Delete deletes a directory document from the database and destroys
56 // the underlying object. Any child directories and files must have been
57 // deleted first by the caller
58 func (dir *Directory) Delete() error {
59 return errorWrap(C.notmuch_directory_delete(dir.dir))
60 }
61
62 func (dir *Directory) Close() {
63 C.notmuch_directory_destroy(dir.dir)
64 }