Changeset 80


Ignore:
Timestamp:
07/17/09 13:31:39 (3 years ago)
Author:
dom
Message:

Fixed more bugs in directory_watcher.

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/TODO

    r79 r80  
    11-*- mode: text -*- 
    22 
    3 Known bugs: 
    4 ---------- 
     3Known issues: 
     4------------ 
    55 
    6 text_printer probably prints too many \n when two errors in a row. 
     6- text_printer doesn't yet handle file removals. 
     7- fixtures:make_tree doesn't like {file, "a", "a"} in tree. 
    78 
    89Check for possible bugs: 
  • trunk/src/compiler_test.erl

    r71 r80  
    1616 
    1717compiles_and_reports_progress_warnings_and_errors () -> 
    18     Compiler = spawn_link (compiler, init, [notify_me (), "fix"]), 
     18    Compiler = spawn_link (compiler, init, [notify_me (), "/home/dom/forge/fix"]), 
    1919    Compiler ! check, 
    2020    Ms = receive_all (), 
     
    2323 
    2424stops () -> 
    25     Compiler = spawn_link (compiler, init, [notify_me (), "fix"]), 
     25    Compiler = spawn_link (compiler, init, [notify_me (), "/home/com/forge/fix"]), 
    2626    Compiler ! check, 
    2727    receive_all (), 
  • trunk/src/directory_watcher.erl

    r75 r80  
    66-export ([init/2]). 
    77-export ([init_recursive/2]). 
    8 -export([start_io/2]). 
    9 -export([start_io/0]). 
    108-include_lib ("kernel/include/file.hrl"). 
    119 
    12 start_io () -> 
    13     start_io (".", 3000). 
    14  
    15 start_io (Dir, Interval) -> 
    16     Watcher = spawn_link (?MODULE, init_recursive, [Dir, self ()]), 
    17     io_loop (Interval, Watcher). 
    18  
    19 io_loop (Interval, Watcher) -> 
    20     Watcher ! check, 
    21     receive 
    22         {directory_watcher, _, Event} -> 
    23             io: fwrite ("~p~n", [Event]), 
    24             io_loop (Interval, Watcher); 
    25         stop -> 
    26             bye 
    27     after Interval -> 
    28             io_loop (Interval, Watcher) 
    29     end. 
    30  
    3110init (Directory, F) -> 
    32     check (Directory, F, []). 
     11    D = filename: absname (Directory), 
     12    check (D, F, []). 
    3313 
    3414init_recursive (Directory, F) -> 
     15    D = filename: absname (Directory), 
    3516    Self = self (), 
    36     Watcher = spawn_link (?MODULE, init, [Directory, send (Self)]), 
    37     loop_recursive (Directory, F, [Watcher]). 
     17    Watcher = spawn_link (?MODULE, init, [D, send (Self)]), 
     18    loop_recursive (D, F, [Watcher]). 
    3819 
    3920check (Directory, F, State) -> 
    4021    New_state = list_dir (Directory, F), 
    41     compare (F, State, New_state), 
     22    sort_and_compare (F, State, New_state), 
    4223    loop (Directory, F, New_state). 
    4324 
     
    9980    end. 
    10081 
    101 compare (_, State, State) -> 
    102     done; 
    103 compare (Fun, [X | Xs], [X | Ys]) -> 
    104     compare (Fun, Xs, Ys); 
    105 compare (Fun, [{F, {regular, _}} | Xs], [{F, {regular, _}} | Ys]) -> 
    106     report_changed (Fun, F), 
    107     compare (Fun, Xs, Ys); 
    108 compare (Fun, [{F, _}=X | Xs], [{F, _} | Ys]) -> 
    109     report_lost (Fun, X), 
    110     report_found (Fun, F), 
    111     compare (Fun, Xs, Ys); 
    112 compare (Fun, [X, {F, V} | Xs], [{F, W} | Ys]) -> 
    113     report_lost (Fun, X), 
    114     compare (Fun, [{F, V} | Xs], [{F, W} | Ys]); 
    115 compare (Fun, [{F, V} | Xs], [Y, {F, W} | Ys]) -> 
    116     {Filename, _} = Y, 
    117     report_found (Fun, Filename), 
    118     compare (Fun, [{F, V} | Xs], [{F, W} | Ys]); 
    119 compare (Fun, [], [Y | Ys]) -> 
    120     {Filename, _} = Y, 
    121     report_found (Fun, Filename), 
    122     compare (Fun, [], Ys); 
    123 compare (Fun, [X | Xs], []) -> 
    124     report_lost (Fun, X), 
    125     compare (Fun, Xs, []); 
    126 compare (Fun, [X], [Y]) -> 
    127     report_lost (Fun, X), 
    128     {File, _} = Y, 
    129     report_found (Fun, File), 
    130     done; 
    131 compare (_, [], []) -> 
     82sort_and_compare (F, Old, New) -> 
     83    Original = dict: from_list (Old), 
     84    Modified = dict: from_list (New), 
     85    Compared = adlib: compare_dict (Modified, Original), 
     86    dict: fold (fun notify_new/3, F, dict: fetch (new, Compared)), 
     87    dict: fold (fun notify_lost/3, F, dict: fetch (lost, Compared)), 
     88    dict: fold (fun notify_changed/3, F, dict: fetch (changed, Compared)), 
    13289    done. 
     90     
     91notify_new (File_name, _, Fun) -> 
     92    report_found (Fun, File_name), 
     93    Fun. 
    13394 
    13495report_found (F, Filename) -> 
    13596    F ({type (Filename), Filename, found}). 
     97 
     98notify_lost (File_name, Value, Fun) -> 
     99    report_lost (Fun, {File_name, Value}), 
     100    Fun. 
    136101 
    137102report_lost (F, {Filename, directory}) -> 
     
    139104report_lost (F, {Filename, {regular, _}}) -> 
    140105    F ({{file, filename: extension (Filename)}, Filename, lost}). 
     106 
     107notify_changed (File_name, {{regular, _}, {regular, _}}, Fun) -> 
     108    report_changed (Fun, File_name), 
     109    Fun; 
     110notify_changed (File_name, {_, Original}, Fun) -> 
     111    report_lost (Fun, {File_name, Original}), 
     112    report_found (Fun, File_name), 
     113    Fun. 
    141114 
    142115report_changed (F, Filename) -> 
  • trunk/src/directory_watcher_test.erl

    r75 r80  
    1717-export ([change_from_file_to_directory_when_recursive/0]). 
    1818-export ([remove_and_add_in_same_check/0]). 
     19-export ([insensitive_to_cwd/0]). 
     20-export ([can_replace_all_in_same_check/0]). 
     21-export ([can_find_two_at_a_time/0]). 
     22-export([tree/0]). 
    1923 
    2024tests_from_empty () -> 
     
    7175remove_and_add_in_same_check () ->     
    7276    F = fun remove_and_add_in_same_check/2, 
     77    ok = fixtures: use_tree ([{file, "foo", "foo"}], F). 
     78 
     79insensitive_to_cwd () -> 
     80    Watcher = spawn_link (directory_watcher, init, ["/home/dom/forge/fix", send_me ()]), 
     81    receive_all (), 
     82    ok = file: set_cwd ("/tmp"), 
     83    Watcher ! check, 
     84    true = is_process_alive (Watcher), 
     85    [] = receive_all (), 
     86    ok. 
     87 
     88can_replace_all_in_same_check () -> 
     89    Tree = [{file, X, X} || X <- ["foo", "bar", "baz"]], 
     90    F = fun can_replace_all_in_same_check/2, 
     91    ok = fixtures: use_tree (Tree, F). 
     92 
     93can_find_two_at_a_time () -> 
     94    F = fun can_find_two_at_a_time/2, 
    7395    ok = fixtures: use_tree ([{file, "foo", "foo"}], F). 
    7496 
     
    267289    ok = file: write_file (Bar, list_to_binary ("bar")), 
    268290    Watcher ! check, 
    269     [{{file, ""}, Foo, lost}, 
    270      {{file, ""}, Bar, found}] = receive_all (), 
    271     ok. 
    272      
     291    [{{file, ""}, Bar, found}, 
     292     {{file, ""}, Foo, lost}] = receive_all (), 
     293    ok. 
     294     
     295can_replace_all_in_same_check (Root, Tree) -> 
     296    Watcher = spawn_link (directory_watcher, init, [Root, send_me ()]), 
     297    receive_all (), 
     298    Replace = fun ({file, F, _}) -> 
     299                     Old = filename: join (Root, F), 
     300                     ok = file: delete (Old), 
     301                      New = filename: join (Root, F ++ F), 
     302                      ok = file: write_file (New, "hello") 
     303             end, 
     304    ok = lists: foreach (Replace, Tree), 
     305    Watcher ! check, 
     306    Lost_files = [filename: join (Root, X) || {file, X, _} <- Tree], 
     307    Found_files = [filename: join (Root, X++X) || {file, X, _} <- Tree], 
     308    Lost = [{{file, ""}, X, lost} || X <- Lost_files], 
     309    Found = [{{file, ""}, X, found} || X <- Found_files], 
     310    Expected = lists: sort (Lost ++ Found), 
     311    Received = lists: sort (receive_all ()), 
     312    {Expected, Expected} = {Expected, Received}, 
     313    ok. 
     314 
     315can_find_two_at_a_time (Root, _) -> 
     316    Watcher = spawn_link (directory_watcher, init, [Root, send_me ()]), 
     317    receive_all (), 
     318    [Bar, Baz] = [filename: join (Root, X) || X <- ["bar", "baz"]], 
     319    ok = file: write_file (Bar, "bar"), 
     320    ok = file: write_file (Baz, "baz"), 
     321    Watcher ! check, 
     322    Found = [{{file, ""}, X, found} || X <- [Bar, Baz]], 
     323    Expected = lists: sort (Found), 
     324    Received = lists: sort (receive_all ()), 
     325    {Expected, Expected} = {Expected, Received}, 
     326    ok. 
    273327 
    274328send_me () -> 
  • trunk/src/shells_tests.erl

    r76 r80  
    1515               compiler_test, compiler, 
    1616               modules_test, modules, 
    17                text_printer_test, text_printer], 
     17               text_printer_test, text_printer, 
     18               adlib_test, adlib], 
    1819    ok = hand_send_to_tester (Modules, Test_node), 
    1920    Caller ! {Caller, done}. 
  • trunk/src/tests_test.erl

    r73 r80  
    1414 
    1515non_tests_returns_empty_list () -> 
    16     Binary = modules: to_binary ("../fix/eg_code.erl"), 
     16    Binary = modules: to_binary ("/home/dom/forge/fix/eg_code.erl"), 
    1717    {_, eg_code, []} = tests: filter_by_attribute (Binary). 
    1818 
    1919test_exports_returns_list_of_tests_from_unloaded_binary () -> 
    20     File = "../fix/eg_test.erl", 
     20    File = "/home/dom/forge/fix/eg_test.erl", 
    2121    Binary = modules: to_binary (File), 
    2222    false = code: is_loaded (eg_test), 
     
    2525 
    2626test_non_exports_also () -> 
    27     File = "../fix/eg_test_not_exports.erl", 
     27    File = "/home/dom/forge/fix/eg_test_not_exports.erl", 
    2828    Binary = modules: to_binary (File), 
    2929    false = code: is_loaded (eg_test_not_exports), 
  • trunk/src/text_printer_test.erl

    r77 r80  
    2424    P ! {self (), compiler, {4, 4, 3}}, 
    2525    <<".\n3/4 successfully compiled.\nCannot run tests.\n">> = receive_io_request (P), 
    26     P ! {self (), compiler, {4, 3, 3}}, 
     26    P ! {self (), compiler, {4, 3, 2}}, 
    2727    <<"Compiling 1: ">> = receive_io_request (P), 
    2828    P ! {self (), compiler, {4, 4, 4}}, 
Note: See TracChangeset for help on using the changeset viewer.