summaryrefslogtreecommitdiff
path: root/rtemstoolkit
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2018-04-14 14:15:07 +1000
committerChris Johns <chrisj@rtems.org>2018-04-14 14:15:07 +1000
commit82c8788b111a4392a56414f8f421ba26ded5d0fd (patch)
tree757c4d3a9f27b56c13687862d66497f51dba5d18 /rtemstoolkit
parentb7c4753de0c17201be0ca047e2a7e320616132cb (diff)
rtemstoolkit/rtl-file: Remove a file on close if requested
Close #3395
Diffstat (limited to 'rtemstoolkit')
-rw-r--r--rtemstoolkit/rld-files.cpp26
-rw-r--r--rtemstoolkit/rld-files.h9
-rw-r--r--rtemstoolkit/rld-outputter.cpp17
-rw-r--r--rtemstoolkit/rld-outputter.h14
4 files changed, 49 insertions, 17 deletions
diff --git a/rtemstoolkit/rld-files.cpp b/rtemstoolkit/rld-files.cpp
index c783f54..fdf12a6 100644
--- a/rtemstoolkit/rld-files.cpp
+++ b/rtemstoolkit/rld-files.cpp
@@ -229,7 +229,8 @@ namespace rld
references_ (0),
fd_ (-1),
symbol_refs (0),
- writable (false)
+ writable (false),
+ remove (false)
{
}
@@ -238,7 +239,8 @@ namespace rld
references_ (0),
fd_ (-1),
symbol_refs (0),
- writable (false)
+ writable (false),
+ remove (false)
{
}
@@ -246,7 +248,8 @@ namespace rld
: references_ (0),
fd_ (-1),
symbol_refs (0),
- writable (false)
+ writable (false),
+ remove (false)
{
}
@@ -255,7 +258,16 @@ namespace rld
if (references_)
std::cerr << "rtl:file:image: references when destructing";
if (fd_ >= 0)
+ {
::close (fd_);
+ if (writable && remove)
+ {
+ if (rld::verbose () >= RLD_VERBOSE_INFO)
+ std::cout << "image::close: removing " << name ().full ()
+ << std::endl;
+ ::unlink (name_.path ().c_str ());
+ }
+ }
}
void
@@ -313,6 +325,14 @@ namespace rld
{
::close (fd_);
fd_ = -1;
+ if (writable && remove)
+ {
+ if (rld::verbose () >= RLD_VERBOSE_INFO)
+ std::cout << "image::close: removing " << name ().full ()
+ << std::endl;
+ ::unlink (name_.path ().c_str ());
+ remove = false;
+ }
}
}
}
diff --git a/rtemstoolkit/rld-files.h b/rtemstoolkit/rld-files.h
index 09e9aaf..f19b732 100644
--- a/rtemstoolkit/rld-files.h
+++ b/rtemstoolkit/rld-files.h
@@ -388,6 +388,14 @@ namespace rld
return writable;
}
+ /**
+ * Remove a writable file on close. This flag can be set when an error
+ * happens while writing a file.
+ */
+ void remove_on_close () {
+ remove = true;
+ }
+
private:
file name_; //< The name of the file.
@@ -396,6 +404,7 @@ namespace rld
elf::file elf_; //< The libelf reference.
int symbol_refs; //< The number of symbols references made.
bool writable; //< The image is writable.
+ bool remove; //< Remove the image on close if writable.
};
/**
diff --git a/rtemstoolkit/rld-outputter.cpp b/rtemstoolkit/rld-outputter.cpp
index 600aedc..9343180 100644
--- a/rtemstoolkit/rld-outputter.cpp
+++ b/rtemstoolkit/rld-outputter.cpp
@@ -332,6 +332,7 @@ namespace rld
catch (...)
{
out.close ();
+ ::unlink (name.c_str ());
throw;
}
@@ -410,6 +411,7 @@ namespace rld
catch (...)
{
delete [] buffer;
+ app.remove_on_close ();
app.close ();
throw;
}
@@ -427,13 +429,13 @@ namespace rld
}
void
- application (const std::string& name,
- const std::string& entry,
- const std::string& exit,
- const files::object_list& dependents,
- const files::cache& cache,
- const symbols::table& symbols,
- bool one_file)
+ rap_application (const std::string& name,
+ const std::string& entry,
+ const std::string& exit,
+ const files::object_list& dependents,
+ const files::cache& cache,
+ const symbols::table& symbols,
+ bool one_file)
{
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << "outputter:application: " << name << std::endl;
@@ -458,6 +460,7 @@ namespace rld
}
catch (...)
{
+ app.remove_on_close ();
app.close ();
throw;
}
diff --git a/rtemstoolkit/rld-outputter.h b/rtemstoolkit/rld-outputter.h
index 7fe52b2..985ae55 100644
--- a/rtemstoolkit/rld-outputter.h
+++ b/rtemstoolkit/rld-outputter.h
@@ -111,13 +111,13 @@ namespace rld
* the user requested.
* @param symbols The symbol table used to resolve the application.
*/
- void application (const std::string& name,
- const std::string& entry,
- const std::string& exit,
- const files::object_list& dependents,
- const files::cache& cache,
- const symbols::table& symbols,
- bool one_file);
+ void rap_application (const std::string& name,
+ const std::string& entry,
+ const std::string& exit,
+ const files::object_list& dependents,
+ const files::cache& cache,
+ const symbols::table& symbols,
+ bool one_file);
}
}