]> git.notmuchmail.org Git - notmuch/blob - bindings/ruby/directory.c
ruby: First attempt at fixing gc for ruby-1.9
[notmuch] / bindings / ruby / directory.c
1 /* The Ruby interface to the notmuch mail library
2  *
3  * Copyright © 2010 Ali Polatel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Ali Polatel <alip@exherbo.org>
19  */
20
21 #include "defs.h"
22
23 /*
24  * call-seq: DIR.mtime => fixnum
25  *
26  * Returns the mtime of the directory or +0+ if no mtime has been previously
27  * stored.
28  */
29 VALUE
30 notmuch_rb_directory_get_mtime(VALUE self)
31 {
32     notmuch_rb_directory_t *dir;
33
34     Data_Get_Struct(self, notmuch_rb_directory_t, dir);
35
36     return UINT2NUM(notmuch_directory_get_mtime(dir->nm_dir));
37 }
38
39 /*
40  * call-seq: DIR.mtime=(fixnum) => nil
41  *
42  * Store an mtime within the database for the directory object.
43  */
44 VALUE
45 notmuch_rb_directory_set_mtime(VALUE self, VALUE mtimev)
46 {
47     notmuch_status_t ret;
48     notmuch_rb_directory_t *dir;
49
50     Data_Get_Struct(self, notmuch_rb_directory_t, dir);
51
52     if (!FIXNUM_P(mtimev))
53         rb_raise(rb_eTypeError, "First argument not a fixnum");
54
55     ret = notmuch_directory_set_mtime(dir->nm_dir, FIX2UINT(mtimev));
56     notmuch_rb_status_raise(ret);
57     return Qtrue;
58 }
59
60 /*
61  * call-seq: DIR.child_files => FILENAMES
62  *
63  * Return a Notmuch::FileNames object, which is an +Enumerable+ listing all the
64  * filenames of messages in the database within the given directory.
65  */
66 VALUE
67 notmuch_rb_directory_get_child_files(VALUE self)
68 {
69     notmuch_rb_directory_t *dir;
70     notmuch_rb_filenames_t *flist;
71     VALUE flistv;
72
73     Data_Get_Struct(self, notmuch_rb_directory_t, dir);
74
75     flistv = Data_Make_Struct(notmuch_rb_cFileNames, notmuch_rb_filenames_t,
76             notmuch_rb_filenames_mark, notmuch_rb_filenames_free, flist);
77     flist->dir = self;
78     flist->nm_flist = notmuch_directory_get_child_files(dir->nm_dir);
79
80     return flistv;
81 }
82
83 /*
84  * call-seq: DIR.child_directories => FILENAMES
85  *
86  * Return a Notmuch::FileNames object, which is an +Enumerable+ listing all the
87  * directories in the database within the given directory.
88  */
89 VALUE
90 notmuch_rb_directory_get_child_directories(VALUE self)
91 {
92     notmuch_rb_directory_t *dir;
93     notmuch_rb_filenames_t *flist;
94     VALUE flistv;
95
96     Data_Get_Struct(self, notmuch_rb_directory_t, dir);
97
98     flistv = Data_Make_Struct(notmuch_rb_cFileNames, notmuch_rb_filenames_t,
99             notmuch_rb_filenames_mark, notmuch_rb_filenames_free, flist);
100     flist->dir = self;
101     flist->nm_flist = notmuch_directory_get_child_directories(dir->nm_dir);
102
103     return flistv;
104 }