Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for overwriting the backup #6

Merged
merged 1 commit into from

2 participants

@hypernumbers

This fix checks if the backup exists and doesn't run if it does.

@hypernumbers hypernumbers Running install.escript more than once overwrites the backup.
This fix checks if the backup exists and doesn't run if it does.
ab82348
@ferd ferd merged commit 4568763 into ferd:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2013
  1. @hypernumbers

    Running install.escript more than once overwrites the backup.

    hypernumbers authored
    This fix checks if the backup exists and doesn't run if it does.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 12 deletions.
  1. +22 −12 install.escript
View
34 install.escript
@@ -3,6 +3,8 @@
-module(install).
-export([main/0, main/1]).
+-define(BACKUP, "group.beam.backup-pre-shell-history").
+
main(_) -> main().
main() ->
@@ -17,16 +19,24 @@ main() ->
),
io:format("Path = ~s~nVersion = ~s~n", [Path, Version]),
- BackupCmd = io_lib:format(
- "cp -n \"~s/group.beam\" \"~s/group.beam.backup-pre-shell-history\"",
- [Path, Path]
- ),
- io:format("Backing up existing file~n"),
- os:cmd(BackupCmd),
+ % check if the backup exists and only continue if it doesn't
+ Backup = lists:flatten(io_lib:format("~s/" ++ ?BACKUP, [Path])),
+ BackupExists = filelib:is_regular(Backup),
+ case BackupExists of
+ true ->
+ ok;
+ false ->
+ BackupCmd = io_lib:format(
+ "cp -n \"~s/group.beam\" \"~s/" ++ ?BACKUP ++ "\"",
+ [Path, Path]
+ ),
+ io:format("Backing up existing file~n"),
+ os:cmd(BackupCmd),
- CopyCmd = io_lib:format(
- "cp ebin/~s/*.beam \"~s\"",
- [Version, Path]
- ),
- io:format("Installing...~n"),
- os:cmd(CopyCmd).
+ CopyCmd = io_lib:format(
+ "cp ebin/~s/*.beam \"~s\"",
+ [Version, Path]
+ ),
+ io:format("Installing...~n"),
+ os:cmd(CopyCmd)
+ end.
Something went wrong with that request. Please try again.