diff options
author | midipix <writeonce@midipix.org> | 2016-04-03 14:08:11 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-04-03 14:08:11 -0400 |
commit | 628cde480b7f092a0e8903f52572b75d0f0f719c (patch) | |
tree | 8f92c905cbb05395fa1c188dd21933fbd544b0d9 | |
parent | 5fff2735d5305fddfaf64b37b4ad395823003d85 (diff) | |
download | slibtool-628cde480b7f092a0e8903f52572b75d0f0f719c.tar.bz2 slibtool-628cde480b7f092a0e8903f52572b75d0f0f719c.tar.xz |
link mode: slbt_exec_link_remove_file(): implementation and integration.
-rw-r--r-- | src/logic/slbt_exec_link.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c index 9f986ff..2c9e5aa 100644 --- a/src/logic/slbt_exec_link.c +++ b/src/logic/slbt_exec_link.c @@ -73,6 +73,21 @@ static bool slbt_adjust_input_argument(char * arg, bool fpic) return true; } +static int slbt_exec_link_remove_file( + const struct slbt_driver_ctx * dctx, + struct slbt_exec_ctx * ectx, + const char * target) +{ + /* remove target (if any) */ + if (!(unlink(target)) || (errno == ENOENT)) + return 0; + + if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) + strerror(errno); + + return -1; +} + static int slbt_exec_link_create_archive( const struct slbt_driver_ctx * dctx, struct slbt_exec_ctx * ectx, @@ -122,6 +137,10 @@ static int slbt_exec_link_create_archive( if (slbt_output_link(dctx,ectx)) return -1; + /* remove old archive as needed */ + if (slbt_exec_link_remove_file(dctx,ectx,output)) + return -1; + /* ar spawn */ if ((slbt_spawn(ectx,true) < 0) || ectx->exitcode) return -1; @@ -155,7 +174,7 @@ static int slbt_exec_link_create_symlink( char * lnkname) { const char * slash; - char * ln[6]; + char * ln[5]; char atarget[PATH_MAX]; /* atarget */ @@ -170,10 +189,9 @@ static int slbt_exec_link_create_symlink( /* ln argv (fake) */ ln[0] = "ln"; - ln[1] = "-f"; - ln[2] = "-s"; - ln[3] = atarget; - ln[4] = lnkname; + ln[1] = "-s"; + ln[2] = atarget; + ln[3] = lnkname; ectx->argv = ln; /* step output */ @@ -181,8 +199,9 @@ static int slbt_exec_link_create_symlink( if (slbt_output_link(dctx,ectx)) return -1; - /* remove old symlink (if any) */ - unlink(lnkname); + /* remove old symlink as needed */ + if (slbt_exec_link_remove_file(dctx,ectx,lnkname)) + return -1; /* create symlink */ return symlink(atarget,lnkname); |