lmkplz 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c8a6721f9750f5fc79f50ede89ec941ed7d4bde
4
- data.tar.gz: 7eeaa733f71134827a9268a54462daf6d6f081e5
3
+ metadata.gz: 12b1bb3e56d8b0eab118f968cdc2f69ac7ac3571
4
+ data.tar.gz: fde8cff5e15710231b96dc82786c9e242c9366a7
5
5
  SHA512:
6
- metadata.gz: 4fdb772e9865bb5d3567556ac551c0552b4006e71e8acbb2e8e2a29e28e9a9a65ab9d624926853dea0f9042f342d1669b191ecf164801bfdc55526642b413da1
7
- data.tar.gz: 6078cf0ba86859c106e4bd9f0e742f80e747fc7339c22016e42240063dce3b9e709c404cbd90894f1c1cdb80a2d59d85ebd22f812aacd7c35f25167c421db12f
6
+ metadata.gz: dbccdbbcf587eacb787b0a8e4f36b46260dc31eaa8771bf6c88ddc154e72135b35d1976f829047d15c0199719c5ee1be1b107634e1c8ba84d1803b12a99f1554
7
+ data.tar.gz: bc21e7c29b04fd2f599f2bf882b6756b6842b50b189d5ad2713e830ba5890693c67cb8ed68ce5c7b2be34d909679ab49780ff6e6c0784f7ab7cd6a03a1a12610
@@ -0,0 +1,238 @@
1
+ [root]
2
+ name = "kkttyl"
3
+ version = "0.0.3"
4
+ dependencies = [
5
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
6
+ "notify 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
7
+ "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
8
+ ]
9
+
10
+ [[package]]
11
+ name = "bitflags"
12
+ version = "0.4.0"
13
+ source = "registry+https://github.com/rust-lang/crates.io-index"
14
+
15
+ [[package]]
16
+ name = "bitflags"
17
+ version = "0.7.0"
18
+ source = "registry+https://github.com/rust-lang/crates.io-index"
19
+
20
+ [[package]]
21
+ name = "bytes"
22
+ version = "0.3.0"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+
25
+ [[package]]
26
+ name = "cfg-if"
27
+ version = "0.1.0"
28
+ source = "registry+https://github.com/rust-lang/crates.io-index"
29
+
30
+ [[package]]
31
+ name = "filetime"
32
+ version = "0.1.10"
33
+ source = "registry+https://github.com/rust-lang/crates.io-index"
34
+ dependencies = [
35
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
36
+ ]
37
+
38
+ [[package]]
39
+ name = "fsevent"
40
+ version = "0.2.16"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ dependencies = [
43
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
44
+ "fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
45
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
46
+ ]
47
+
48
+ [[package]]
49
+ name = "fsevent-sys"
50
+ version = "0.1.6"
51
+ source = "registry+https://github.com/rust-lang/crates.io-index"
52
+ dependencies = [
53
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
54
+ ]
55
+
56
+ [[package]]
57
+ name = "inotify"
58
+ version = "0.3.0"
59
+ source = "registry+https://github.com/rust-lang/crates.io-index"
60
+ dependencies = [
61
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "kernel32-sys"
66
+ version = "0.2.2"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ dependencies = [
69
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
70
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
71
+ ]
72
+
73
+ [[package]]
74
+ name = "libc"
75
+ version = "0.2.22"
76
+ source = "registry+https://github.com/rust-lang/crates.io-index"
77
+
78
+ [[package]]
79
+ name = "log"
80
+ version = "0.3.7"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+
83
+ [[package]]
84
+ name = "mio"
85
+ version = "0.5.1"
86
+ source = "registry+https://github.com/rust-lang/crates.io-index"
87
+ dependencies = [
88
+ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
89
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
90
+ "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
91
+ "miow 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
92
+ "net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
93
+ "nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
94
+ "slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
95
+ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
96
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
97
+ ]
98
+
99
+ [[package]]
100
+ name = "miow"
101
+ version = "0.1.5"
102
+ source = "registry+https://github.com/rust-lang/crates.io-index"
103
+ dependencies = [
104
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
105
+ "net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
106
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
107
+ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
108
+ ]
109
+
110
+ [[package]]
111
+ name = "net2"
112
+ version = "0.2.29"
113
+ source = "registry+https://github.com/rust-lang/crates.io-index"
114
+ dependencies = [
115
+ "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
116
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
117
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
118
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
119
+ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
120
+ ]
121
+
122
+ [[package]]
123
+ name = "nix"
124
+ version = "0.5.1"
125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
126
+ dependencies = [
127
+ "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
128
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
129
+ ]
130
+
131
+ [[package]]
132
+ name = "notify"
133
+ version = "4.0.1"
134
+ source = "registry+https://github.com/rust-lang/crates.io-index"
135
+ dependencies = [
136
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
137
+ "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
138
+ "fsevent 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
139
+ "fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
140
+ "inotify 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
141
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
142
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
143
+ "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
144
+ "walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
145
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
146
+ ]
147
+
148
+ [[package]]
149
+ name = "rand"
150
+ version = "0.3.15"
151
+ source = "registry+https://github.com/rust-lang/crates.io-index"
152
+ dependencies = [
153
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
154
+ ]
155
+
156
+ [[package]]
157
+ name = "redox_syscall"
158
+ version = "0.1.17"
159
+ source = "registry+https://github.com/rust-lang/crates.io-index"
160
+
161
+ [[package]]
162
+ name = "slab"
163
+ version = "0.1.3"
164
+ source = "registry+https://github.com/rust-lang/crates.io-index"
165
+
166
+ [[package]]
167
+ name = "tempdir"
168
+ version = "0.3.5"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ dependencies = [
171
+ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
172
+ ]
173
+
174
+ [[package]]
175
+ name = "time"
176
+ version = "0.1.37"
177
+ source = "registry+https://github.com/rust-lang/crates.io-index"
178
+ dependencies = [
179
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
180
+ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
181
+ "redox_syscall 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
182
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
183
+ ]
184
+
185
+ [[package]]
186
+ name = "walkdir"
187
+ version = "0.1.8"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ dependencies = [
190
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
191
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
192
+ ]
193
+
194
+ [[package]]
195
+ name = "winapi"
196
+ version = "0.2.8"
197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
198
+
199
+ [[package]]
200
+ name = "winapi-build"
201
+ version = "0.1.1"
202
+ source = "registry+https://github.com/rust-lang/crates.io-index"
203
+
204
+ [[package]]
205
+ name = "ws2_32-sys"
206
+ version = "0.2.1"
207
+ source = "registry+https://github.com/rust-lang/crates.io-index"
208
+ dependencies = [
209
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
210
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
211
+ ]
212
+
213
+ [metadata]
214
+ "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
215
+ "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
216
+ "checksum bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c129aff112dcc562970abb69e2508b40850dd24c274761bb50fb8a0067ba6c27"
217
+ "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
218
+ "checksum filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5363ab8e4139b8568a6237db5248646e5a8a2f89bd5ccb02092182b11fd3e922"
219
+ "checksum fsevent 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfe593ebcfc76884138b25426999890b10da8e6a46d01b499d7c54c604672c38"
220
+ "checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874"
221
+ "checksum inotify 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887fcc180136e77a85e6a6128579a719027b1bab9b1c38ea4444244fe262c20c"
222
+ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
223
+ "checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"
224
+ "checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"
225
+ "checksum mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a637d1ca14eacae06296a008fa7ad955347e34efcb5891cfd8ba05491a37907e"
226
+ "checksum miow 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3e690c5df6b2f60acd45d56378981e827ff8295562fc8d34f573deb267a59cd1"
227
+ "checksum net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "bc01404e7568680f1259aa5729539f221cb1e6d047a0d9053cab4be8a73b5d67"
228
+ "checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79"
229
+ "checksum notify 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "298d4401ff2c6cebb7f8944c90288647c89ce59029d43b439444cf1067df55e1"
230
+ "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
231
+ "checksum redox_syscall 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "29dbdfd4b9df8ab31dec47c6087b7b13cbf4a776f335e4de8efba8288dda075b"
232
+ "checksum slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d807fd58c4181bbabed77cb3b891ba9748241a552bcc5be698faaebefc54f46e"
233
+ "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
234
+ "checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3"
235
+ "checksum walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780"
236
+ "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
237
+ "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
238
+ "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
@@ -0,0 +1,15 @@
1
+ [package]
2
+ name = "kkttyl"
3
+ version = "0.0.3"
4
+ authors = ["Zach Ahn <engineering@zachahn.com>"]
5
+
6
+ [lib]
7
+ name = "kkttyl"
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ notify = "4.0.1"
12
+ libc = "0.2.22"
13
+
14
+ [dev-dependencies]
15
+ tempdir = "^0.3.5"
@@ -0,0 +1,3 @@
1
+ pub fn wrap_no_arg(callback: extern "C" fn()) -> Box<Fn()> {
2
+ Box::new(move || callback())
3
+ }
@@ -0,0 +1,118 @@
1
+ extern crate notify;
2
+ extern crate libc;
3
+
4
+ mod safe_wrapper;
5
+ mod callback_util;
6
+ mod string_util;
7
+
8
+ use libc::c_char;
9
+ use std::ffi::CStr;
10
+ use std::path::PathBuf;
11
+ use safe_wrapper::KkttylStruct;
12
+
13
+ /// Create a new instance of the watcher
14
+ #[no_mangle]
15
+ pub extern "C" fn kkttyl_new(debounce_duration: u64) -> *mut KkttylStruct {
16
+ let boxed_kkttyl = safe_wrapper::safe_kkttyl_new(debounce_duration);
17
+
18
+ Box::into_raw(boxed_kkttyl)
19
+ }
20
+
21
+ /// Add a path to watch
22
+ #[no_mangle]
23
+ pub extern "C" fn kkttyl_add(kkttyl: *mut KkttylStruct, abspath: *const c_char) {
24
+ let unsafe_abspath = unsafe { CStr::from_ptr(abspath) };
25
+ let actual = unsafe { &mut *kkttyl };
26
+
27
+ safe_wrapper::safe_kkttyl_add(actual, unsafe_abspath.to_str().unwrap());
28
+ }
29
+
30
+ /// Be notified of a change
31
+ #[no_mangle]
32
+ pub extern "C" fn kkttyl_await(
33
+ kkttyl: *mut KkttylStruct,
34
+ timeout_duration: u64,
35
+ success: extern "C" fn(*const c_char, *const c_char, *const c_char),
36
+ failure: extern "C" fn(),
37
+ timeout: extern "C" fn(),
38
+ ended: extern "C" fn(),
39
+ ) {
40
+ let actual = unsafe { &mut *kkttyl };
41
+
42
+ let wrapped_success_callback = success_callback_wrapper(success);
43
+ let wrapped_failure_callback = callback_util::wrap_no_arg(failure);
44
+ let wrapped_timeout_callback = callback_util::wrap_no_arg(timeout);
45
+ let wrapped_ended_callback = callback_util::wrap_no_arg(ended);
46
+
47
+ safe_wrapper::safe_kkttyl_await(
48
+ actual,
49
+ timeout_duration,
50
+ &*wrapped_success_callback,
51
+ &*wrapped_failure_callback,
52
+ &*wrapped_timeout_callback,
53
+ &*wrapped_ended_callback,
54
+ )
55
+ }
56
+
57
+ /// Free!
58
+ #[no_mangle]
59
+ pub extern "C" fn kkttyl_free(kkttyl: *mut KkttylStruct) {
60
+ if kkttyl.is_null() {
61
+ return;
62
+ }
63
+
64
+ unsafe {
65
+ Box::from_raw(kkttyl);
66
+ }
67
+ }
68
+
69
+ fn success_callback_wrapper(
70
+ callback: extern "C" fn(*const c_char, *const c_char, *const c_char),
71
+ ) -> Box<Fn(PathBuf, PathBuf, PathBuf)> {
72
+ Box::new(move |modified_pathbuf, created_cstring, removed_pathbuf| {
73
+ let modified_cstring = string_util::pathbuf_to_cstring(modified_pathbuf);
74
+ let created_cstring = string_util::pathbuf_to_cstring(created_cstring);
75
+ let removed_cstring = string_util::pathbuf_to_cstring(removed_pathbuf);
76
+
77
+ callback(
78
+ modified_cstring.as_ptr(),
79
+ created_cstring.as_ptr(),
80
+ removed_cstring.as_ptr(),
81
+ );
82
+ })
83
+ }
84
+
85
+ #[cfg(test)]
86
+ mod tests {
87
+ extern crate tempdir;
88
+
89
+ use super::*;
90
+ use self::tempdir::TempDir;
91
+ use std::thread::sleep;
92
+ use std::fs::File;
93
+ use std::time::Duration;
94
+ use std::io::prelude::*;
95
+ use std::ffi::CString;
96
+
97
+ #[test]
98
+ fn unsafe_works() {
99
+ let td = TempDir::new("tmpdir").expect("failed to create tempdir");
100
+
101
+ sleep(Duration::from_millis(10));
102
+
103
+ let kkttyl = kkttyl_new(1);
104
+ let path_to_watch = td.path().to_str().expect("can't get tempdir path");
105
+ kkttyl_add(kkttyl, CString::new(path_to_watch).unwrap().as_ptr());
106
+
107
+ sleep(Duration::from_millis(100));
108
+
109
+ let file_path = td.path().join("testing.txt");
110
+ let mut f = File::create(file_path).expect("couldn't create file");
111
+ f.write_all(b"Hello, world!").expect(
112
+ "couldn't write to file",
113
+ );
114
+ f.sync_all().expect("couldn't sync file");
115
+
116
+ unsafe { (*kkttyl).rx.recv().expect("didn't get file") };
117
+ }
118
+ }
@@ -0,0 +1,119 @@
1
+ use notify::{RecommendedWatcher, Watcher, RecursiveMode, DebouncedEvent};
2
+ use std::sync::mpsc::{channel, Receiver};
3
+ use std::time::Duration;
4
+ use std::path::PathBuf;
5
+ use std::sync::mpsc;
6
+
7
+ pub struct KkttylStruct {
8
+ pub watcher: RecommendedWatcher,
9
+ pub rx: Receiver<DebouncedEvent>,
10
+ }
11
+
12
+ pub fn safe_kkttyl_new(debounce_duration: u64) -> Box<KkttylStruct> {
13
+ let (transmission, receiving) = channel();
14
+ let watcher: RecommendedWatcher =
15
+ Watcher::new(transmission, Duration::from_millis(debounce_duration)).unwrap();
16
+
17
+ let ws = KkttylStruct {
18
+ watcher: watcher,
19
+ rx: receiving,
20
+ };
21
+
22
+ Box::new(ws)
23
+ }
24
+
25
+ pub fn safe_kkttyl_add(kkttyl: &mut KkttylStruct, abspath: &str) {
26
+ kkttyl
27
+ .watcher
28
+ .watch(abspath, RecursiveMode::Recursive)
29
+ .unwrap();
30
+ }
31
+
32
+ pub fn safe_kkttyl_await(
33
+ kkttyl: &mut KkttylStruct,
34
+ timeout_duration: u64,
35
+ success_callback: &Fn(PathBuf, PathBuf, PathBuf),
36
+ failure_callback: &Fn(),
37
+ timeout_callback: &Fn(),
38
+ ended_callback: &Fn(),
39
+ ) {
40
+ match kkttyl.rx.recv_timeout(
41
+ Duration::from_millis(timeout_duration),
42
+ ) {
43
+ Ok(notify_event) => {
44
+ match notify_event {
45
+ DebouncedEvent::Create(pathbuf) => {
46
+ success_callback(PathBuf::new(), pathbuf, PathBuf::new())
47
+ }
48
+ DebouncedEvent::Write(pathbuf) => {
49
+ success_callback(pathbuf, PathBuf::new(), PathBuf::new())
50
+ }
51
+ DebouncedEvent::Remove(pathbuf) => {
52
+ success_callback(PathBuf::new(), PathBuf::new(), pathbuf)
53
+ }
54
+ DebouncedEvent::Rename(sourcepath, destpath) => {
55
+ success_callback(PathBuf::new(), destpath, sourcepath)
56
+ }
57
+ _ => failure_callback(),
58
+ };
59
+ }
60
+ Err(error) => {
61
+ match error {
62
+ mpsc::RecvTimeoutError::Timeout => timeout_callback(),
63
+ mpsc::RecvTimeoutError::Disconnected => ended_callback(),
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ #[cfg(test)]
70
+ mod tests {
71
+ extern crate tempdir;
72
+
73
+ use super::*;
74
+ use self::tempdir::TempDir;
75
+ use std::thread::sleep;
76
+ use std::fs::File;
77
+ use std::io::prelude::*;
78
+
79
+ #[test]
80
+ fn safe_works() {
81
+ let td = TempDir::new("tmpdir").expect("failed to create tempdir");
82
+
83
+ sleep(Duration::from_millis(10));
84
+
85
+ let mut kkttyl = safe_kkttyl_new(1);
86
+ safe_kkttyl_add(
87
+ &mut kkttyl,
88
+ td.path().to_str().expect("can't get tempdir path"),
89
+ );
90
+
91
+ sleep(Duration::from_millis(100));
92
+
93
+ let file_path = td.path().join("testing.txt");
94
+ let mut f = File::create(file_path).expect("couldn't create file");
95
+ f.write_all(b"Hello, world!").expect(
96
+ "couldn't write to file",
97
+ );
98
+ f.sync_all().expect("couldn't sync file");
99
+
100
+ let success_cb = Box::new(move |_m: PathBuf, _a: PathBuf, _r: PathBuf| {});
101
+
102
+ let failure_cb = Box::new(move || {});
103
+
104
+ let timeout_cb = Box::new(move || {});
105
+
106
+ let ended_cb = Box::new(move || {});
107
+
108
+ safe_kkttyl_await(
109
+ &mut kkttyl,
110
+ 400,
111
+ &*success_cb,
112
+ &*failure_cb,
113
+ &*timeout_cb,
114
+ &*ended_cb,
115
+ );
116
+
117
+ // kkttyl.rx.recv().expect("didn't get file");
118
+ }
119
+ }
@@ -0,0 +1,8 @@
1
+ use std::path::PathBuf;
2
+ use std::ffi::CString;
3
+
4
+ pub fn pathbuf_to_cstring(pathbuf: PathBuf) -> CString {
5
+ let path_str = pathbuf.to_str().unwrap();
6
+
7
+ CString::new(path_str).unwrap()
8
+ }
@@ -1,3 +1,3 @@
1
1
  module Lmkplz
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
data/lmkplz.gemspec CHANGED
@@ -16,9 +16,9 @@ Gem::Specification.new do |spec|
16
16
  `git ls-files -z`
17
17
  .split("\x0")
18
18
  .+(Dir.glob("ext/kkttyl/target/release/libkkttyl.*"))
19
- .reject { |f| f.match(%r{^(bin|test|spec|features|ext)/}) }
19
+ .reject { |f| f.match(%r{^(bin|test|spec|features)/}) }
20
20
  .reject { |f| f == "Rakefile" }
21
- .reject { |f| f.match(/^\./) }
21
+ .reject { |f| File.basename(f)[0] == "." }
22
22
  .reject { |f| f.match(%r{\Aext/kkttyl/.*\.d\z}) }
23
23
  spec.bindir = "exe"
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lmkplz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-23 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -118,6 +118,13 @@ files:
118
118
  - Gemfile
119
119
  - LICENSE.txt
120
120
  - README.md
121
+ - ext/kkttyl/Cargo.lock
122
+ - ext/kkttyl/Cargo.toml
123
+ - ext/kkttyl/src/callback_util.rs
124
+ - ext/kkttyl/src/lib.rs
125
+ - ext/kkttyl/src/safe_wrapper.rs
126
+ - ext/kkttyl/src/string_util.rs
127
+ - ext/kkttyl/target/release/libkkttyl.dylib
121
128
  - lib/lmkplz.rb
122
129
  - lib/lmkplz/encasement.rb
123
130
  - lib/lmkplz/file_filter.rb