Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed dir to new interface format

  • Loading branch information...
commit 193151735a9da4cb0cf67fbe1cc7ca28b2c248f9 1 parent c7a9781
Gianfranco authored
Showing with 58 additions and 41 deletions.
  1. +35 −23 src/frame_axiom.erl
  2. +23 −18 test/frame_axiom_tests.erl
View
58 src/frame_axiom.erl
@@ -28,11 +28,7 @@
-export([diff/2,
diff/3]).
-snapshot({D,Path}) when D == dir_detailed ;
- D == dir ->
- snapshot(ets:new(snapshot,[private]),{D,Path});
-snapshot(SnapShot) when SnapShot == port;
- SnapShot == node;
+snapshot(SnapShot) when SnapShot == node;
SnapShot == named_process ->
snapshot(ets:new(snapshot,[private]),SnapShot);
snapshot(SnapShots) when is_list(SnapShots) ->
@@ -62,6 +58,9 @@ snapshot(Ets,{port,all}) ->
snapshot(Ets,{port,Options}) when is_list(Options) ->
lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,port,Option)
end,Ets,Options);
+snapshot(Ets,{dir,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,dir,Option)
+ end,Ets,Options);
snapshot(Ets,ets) ->
Existing = ets:all(),
@@ -71,10 +70,6 @@ snapshot(Ets,{dir,Path}) ->
Structure = collect(false,Path),
ets:insert(Ets,{{dir,Path},Structure}),
Ets;
-snapshot(Ets,{dir_detailed,Path}) ->
- Structure = collect(true,Path),
- ets:insert(Ets,{{dir_detailed,Path},Structure}),
- Ets;
snapshot(Ets,node) ->
Current = nodes(),
ets:insert(Ets,{node,Current}),
@@ -139,8 +134,19 @@ snapshot(Ets,port,opened) ->
snapshot(Ets,port,closed) ->
Ports = erlang:ports(),
ets:insert(Ets,{{port,closed},Ports}),
+ Ets;
+snapshot(Ets,dir,{creation,Path}) ->
+ Current = collect(false,Path),
+ ets:insert(Ets,{{creation,Path},Current}),
+ Ets;
+snapshot(Ets,dir,{deletion,Path}) ->
+ Current = collect(false,Path),
+ ets:insert(Ets,{{deletion,Path},Current}),
+ Ets;
+snapshot(Ets,dir,{content_changes,Path}) ->
+ Current = collect(true,Path),
+ ets:insert(Ets,{{content_changes,Path},Current}),
Ets.
-
diff(Ets,[X]) ->
diff(Ets,X);
@@ -168,6 +174,9 @@ diff(Ets,{port,all}) ->
diff(Ets,{port,Options}) when is_list(Options) ->
lists:foldl(fun(Option,Res) -> Res++diff(Ets,port,Option)
end,[],Options);
+diff(Ets,{dir,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,Res) -> Res++diff(Ets,dir,Option)
+ end,[],Options);
diff(Ets,ets) ->
Current = ets:all(),
@@ -179,11 +188,6 @@ diff(Ets,{dir,Path}) ->
[{{dir,Path},Recorded}] = ets:lookup(Ets,{dir,Path}),
{Created,Deleted} = split(created,deleted,Current,Recorded),
Created++Deleted;
-diff(Ets,{dir_detailed,Path}) ->
- Current = collect(true,Path),
- [{{dir_detailed,Path},Recorded}] = ets:lookup(Ets,{dir_detailed,Path}),
- Changed = contents_changed(Recorded,Current),
- Changed;
diff(Ets,node) ->
Current = nodes(),
[{node,Recorded}] = ets:lookup(Ets,node),
@@ -284,14 +288,22 @@ diff(Ets,port,closed) ->
Current = erlang:ports(),
Key = {port,closed},
[{Key,Recorded}] = ets:lookup(Ets,Key),
- [{closed,C}||C<-Recorded,not lists:member(C,Current)].
-
-
-
-
-
-
-
+ [{closed,C}||C<-Recorded,not lists:member(C,Current)];
+diff(Ets,dir,{creation,Path}) ->
+ Current = collect(false,Path),
+ Key = {creation,Path},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ [{created,C}||C<-Current,not lists:member(C,Recorded)];
+diff(Ets,dir,{deletion,Path}) ->
+ Current = collect(false,Path),
+ Key = {deletion,Path},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ [{deleted,C}||C<-Recorded,not lists:member(C,Current)];
+diff(Ets,dir,{content_changes,Path}) ->
+ Current = collect(true,Path),
+ Key = {content_changes,Path},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ contents_changed(Recorded,Current).
%% Helpers section
View
41 test/frame_axiom_tests.erl
@@ -242,55 +242,60 @@ ports_all_no_change_diff_test() ->
%% ---------------------------------------------------------
file_direct_under_creation_diff_test() ->
Path = ".",
- Ref = frame_axiom:snapshot({dir,Path}),
+ Options = [{creation,Path}],
+ Ref = frame_axiom:snapshot([{dir,Options}]),
Name= "created_this.txt",
file:write_file(Name,"HelloWorld"),
FilePath = filename:join(Path,Name),
- ?assertEqual([{created,{file,FilePath}}],frame_axiom:diff(Ref,{dir,Path})),
+ ?assertEqual([{created,{file,FilePath}}],frame_axiom:diff(Ref,[{dir,Options}])),
file:delete(FilePath).
file_direct_under_deletion_diff_test() ->
Path = ".",
+ Options = [{deletion,Path}],
Name= "created_this.txt",
file:write_file(Name,"HelloWorld"),
- Ref = frame_axiom:snapshot({dir,Path}),
+ Ref = frame_axiom:snapshot([{dir,Options}]),
FilePath = filename:join(Path,Name),
file:delete(FilePath),
- ?assertEqual([{deleted,{file,FilePath}}],frame_axiom:diff(Ref,{dir,Path})).
-
-file_no_change_diff_test() ->
- Path = ".",
- Ref = frame_axiom:snapshot({dir,Path}),
- ?assertEqual([],frame_axiom:diff(Ref,{dir,Path})).
+ ?assertEqual([{deleted,{file,FilePath}}],frame_axiom:diff(Ref,[{dir,Options}])).
file_directory_creation_test() ->
Path = ".",
+ Options = [{creation,Path}],
Name= "this_dir",
- Ref = frame_axiom:snapshot({dir,Path}),
+ Ref = frame_axiom:snapshot([{dir,Options}]),
FullPath = filename:join(Path,Name),
ok = filelib:ensure_dir(FullPath++"/"),
- ?assertEqual([{created,{dir,FullPath}}],frame_axiom:diff(Ref,{dir,Path})),
+ ?assertEqual([{created,{dir,FullPath}}],frame_axiom:diff(Ref,[{dir,Options}])),
file:del_dir(FullPath).
file_directory_deletion_test() ->
Path = ".",
+ Options = [{deletion,Path}],
Name= "this_dir",
FullPath = filename:join(Path,Name),
ok = filelib:ensure_dir(FullPath++"/"),
- Ref = frame_axiom:snapshot({dir,Path}),
+ Ref = frame_axiom:snapshot([{dir,Options}]),
file:del_dir(FullPath),
- ?assertEqual([{deleted,{dir,FullPath}}],frame_axiom:diff(Ref,{dir,Path})).
+ ?assertEqual([{deleted,{dir,FullPath}}],frame_axiom:diff(Ref,[{dir,Options}])).
-%% file system, detailed tests (size, contents)
-%% ----------------------------------------------------------
file_contents_changed_test() ->
Path = ".",
- Name = "this_file.txt",
+ Options = [{content_changes,Path}],
+ Name = "this_file.txt",
FilePath = filename:join(Path,Name),
file:write_file(Name,"Hello_World"),
- Ref = frame_axiom:snapshot({dir_detailed,Path}),
+ Ref = frame_axiom:snapshot([{dir,Options}]),
file:write_file(Name,"Wello_Horld"),
- ?assertEqual([{content_changed,FilePath}],frame_axiom:diff(Ref,{dir_detailed,Path})).
+ ?assertEqual([{content_changed,FilePath}],frame_axiom:diff(Ref,[{dir,Options}])).
+
+file_no_change_all_diff_test() ->
+ Path = ".",
+ Options = {all,Path},
+ Ref = frame_axiom:snapshot([{dir,Options}]),
+ ?assertEqual([],frame_axiom:diff(Ref,[{dir,Options}])).
+
%% node
%% ---------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.