Changeset 50


Ignore:
Timestamp:
04/15/09 02:58:13 (3 years ago)
Author:
dom
Message:

Start adding recursivity to directory_watcher (with Charpi).

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/directory_watcher.erl

    r49 r50  
    55-module (directory_watcher). 
    66-export ([init/3]). 
     7-export ([recursive/1]). 
    78-include_lib ("kernel/include/file.hrl"). 
     9 
     10recursive (Fun) -> 
     11    fun (directory, P, found, S) -> 
     12            spawn_link (directory_watcher, init, [P, Fun, S]); 
     13        (T, E, P, S) -> 
     14            Fun (T, E, P, S) 
     15    end. 
    816 
    917init (Directory, Action, Action_state) -> 
  • trunk/src/directory_watcher_test.erl

    r49 r50  
    99-export ([tests_with_several/0]). 
    1010-export ([bad_symlinks_are_ignored/0]). 
     11-export ([recursive/0]). 
    1112 
    1213tests_from_empty () -> 
     
    3637    ok = fixtures: use_tree ([], fun bad_symlinks_are_ignored/2). 
    3738 
     39recursive () -> 
     40    Tree = [{file, "foo.txt", "Hello"}, 
     41            {file, "bar.txt", "G'day"}, 
     42            {file, "toto.erl", "-module(toto)."}, 
     43            {directory, "subdir", [{file, "subfile.ext", "toto"}]}], 
     44    ok = fixtures: use_tree (Tree, fun recursive/2). 
     45 
     46recursive (Dir, _) -> 
     47    Notify = directory_watcher: recursive (notify ()), 
     48    Watcher = spawn_link (directory_watcher, init, [Dir, Notify, ignore]), 
     49    Filename = filename: join ([Dir, "subdir", "subfile.ext"]), 
     50    Expected = {watcher, {file, ".ext"}, Filename, found, ignore}, 
     51    ok = receive_until_found (Expected). 
     52 
    3853bad_symlinks_are_ignored (Dir, _) -> 
    3954    Watcher = spawn_link (directory_watcher, init, [Dir, notify (), ignore]), 
     
    5368    Watcher = spawn_link (directory_watcher, init, [Dir, notify (), State]), 
    5469    timeout = receive_one (), 
    55  
     70     
    5671    Filename = filename: join (Dir, "myfile.txt"), 
    5772    ok = file: write_file (Filename, list_to_binary ("Hello")), 
     
    120135receive_one () -> 
    121136    receive M -> M after 500 -> timeout end. 
     137 
     138receive_until_found (Message) -> 
     139    receive Message -> ok after 500 -> timeout end. 
Note: See TracChangeset for help on using the changeset viewer.