- Timestamp:
- 04/16/09 20:21:33 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
directory_watcher.erl (modified) (2 diffs)
-
directory_watcher_test.erl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/directory_watcher.erl
r52 r53 5 5 -module (directory_watcher). 6 6 -export ([init/2]). 7 %% -export ([recursive/1]).7 -export ([init_recursive/2]). 8 8 -include_lib ("kernel/include/file.hrl"). 9 10 %% recursive (Fun) ->11 %% fun (directory, P, found) ->12 %% spawn_link (directory_watcher, init, [P, Fun]);13 %% (T, E, P) ->14 %% Fun (T, E, P)15 %% end.16 9 17 10 init (Directory, Pid) -> 18 11 check (Directory, Pid, []). 12 13 init_recursive (Directory, Pid) -> 14 Watcher = spawn_link (?MODULE, init, [Directory, self ()]), 15 loop_recursive (Directory, Pid, [Watcher]). 19 16 20 17 check (Directory, Pid, State) -> … … 54 51 check -> 55 52 check (Directory, Pid, Filenames); 53 stop -> 54 notify (Pid, bye) 55 end. 56 57 loop_recursive (Directory, Pid, Watchers) -> 58 receive 59 {?MODULE, _, {directory, Dir, found}=Event} -> 60 Watcher = spawn_link (?MODULE, init, [Dir, self ()]), 61 notify (Pid, Event), 62 loop_recursive (Directory, Pid, [Watcher | Watchers]); 63 {?MODULE, _, Event} -> 64 notify (Pid, Event), 65 loop_recursive (Directory, Pid, Watchers); 66 check -> 67 lists: foreach (fun (P) -> P ! check end, Watchers); 56 68 stop -> 57 69 notify (Pid, bye) -
trunk/src/directory_watcher_test.erl
r52 r53 9 9 -export ([tests_with_several/0]). 10 10 -export ([bad_symlinks_are_ignored/0]). 11 %%-export ([recursive/0]).11 -export ([recursive/0]). 12 12 13 13 tests_from_empty () -> … … 36 36 ok = fixtures: use_tree ([], fun bad_symlinks_are_ignored/2). 37 37 38 %%recursive () ->39 %%Tree = [{file, "foo.txt", "Hello"},40 %%{file, "bar.txt", "G'day"},41 %%{file, "toto.erl", "-module(toto)."},42 %%{directory, "subdir", [{file, "subfile.ext", "toto"}]}],43 %%ok = fixtures: use_tree (Tree, fun recursive/2).38 recursive () -> 39 Tree = [{file, "foo.txt", "Hello"}, 40 {file, "bar.txt", "G'day"}, 41 {file, "toto.erl", "-module(toto)."}, 42 {directory, "subdir", [{file, "subfile.ext", "toto"}]}], 43 ok = fixtures: use_tree (Tree, fun recursive/2). 44 44 45 %% recursive (Dir, _) -> 46 %% Notify = directory_watcher: recursive (notify ()), 47 %% Watcher = spawn_link (directory_watcher, init, [Dir, Notify]), 48 %% Filename = filename: join ([Dir, "subdir", "subfile.ext"]), 49 %% Expected = {watcher, {file, ".ext"}, Filename, found}, 50 %% ok = receive_until_found (Expected). 45 recursive (Dir, _) -> 46 Watcher = spawn_link (directory_watcher, init_recursive, [Dir, self ()]), 47 Filename = filename: join ([Dir, "subdir", "subfile.ext"]), 48 Expected = {{file, ".ext"}, Filename, found}, 49 ok = receive_until_found (Expected). 51 50 52 51 bad_symlinks_are_ignored (Dir, _) -> … … 127 126 end. 128 127 129 %% receive_until_found (Message) -> 130 %% receive Message -> ok after 500 -> timeout end. 128 receive_until_found (Event) -> 129 receive {directory_watcher, _, Event} -> ok 130 after 500 -> timeout 131 end.
Note: See TracChangeset
for help on using the changeset viewer.
