summaryrefslogtreecommitdiff
path: root/src/rebar_file_utils.erl
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2015-01-19 08:31:15 -0600
committerTristan Sloughter <tristan.sloughter@gmail.com>2015-01-19 08:31:15 -0600
commit488d70d2f249835a61053469dcc6d8dd89a77f96 (patch)
treeaeaaa24d0991eb0443aef9f4dbfbc5ca610ce92c /src/rebar_file_utils.erl
parent5528007751fa534a320c27f46552c15b3ec3028d (diff)
parentf94108e1641d22b66e236e7c29638e5e0f2452ab (diff)
Merge pull request #101 from talentdeficit/file_utils
generalize some temporary directory handling and add it to `rebar_file_utils`
Diffstat (limited to 'src/rebar_file_utils.erl')
-rw-r--r--src/rebar_file_utils.erl32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl
index 0fc1403..8fe8965 100644
--- a/src/rebar_file_utils.erl
+++ b/src/rebar_file_utils.erl
@@ -30,7 +30,10 @@
cp_r/2,
mv/2,
delete_each/1,
- write_file_if_contents_differ/2]).
+ write_file_if_contents_differ/2,
+ system_tmpdir/0,
+ system_tmpdir/1,
+ reset_dir/1]).
-include("rebar.hrl").
@@ -123,6 +126,33 @@ write_file_if_contents_differ(Filename, Bytes) ->
file:write_file(Filename, ToWrite)
end.
+%% returns an os appropriate tmpdir given a path
+-spec system_tmpdir() -> file:filename().
+-spec system_tmpdir(PathComponents) -> file:filename() when
+ PathComponents :: [file:name()].
+
+system_tmpdir() -> system_tmpdir([]).
+system_tmpdir(PathComponents) ->
+ Tmp = case erlang:system_info(system_architecture) of
+ "win32" ->
+ "./tmp";
+ _SysArch ->
+ "/tmp"
+ end,
+ filename:join([Tmp|PathComponents]).
+
+%% recursively removes a directory and then recreates the same
+%% directory but empty
+-spec reset_dir(Path) -> ok | {error, Reason} when
+ Path :: file:name(),
+ Reason :: file:posix().
+
+reset_dir(Path) ->
+ %% delete the directory if it exists
+ _ = ec_file:remove(Path, [recursive]),
+ %% recreate the directory
+ filelib:ensure_dir(filename:join([Path, "dummy.beam"])).
+
%% ===================================================================
%% Internal functions
%% ===================================================================