You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/10/24 15:43:59 UTC

[mynewt-core] branch master updated: sim: Unlink temporary `native_flash.XXXXXX` files

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new c3c7c59  sim: Unlink temporary `native_flash.XXXXXX` files
c3c7c59 is described below

commit c3c7c59de779b0785a8a6e06397df9e9845ba76c
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Oct 23 13:45:46 2018 -0700

    sim: Unlink temporary `native_flash.XXXXXX` files
    
    When the user does not specify a flash filename, sim uses one of these
    temporary files.  In this case, unlink the file immediately after
    opening it.  This prevents the user's `/tmp` directory from filling up
    with these files.
---
 hw/mcu/native/src/hal_flash.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/mcu/native/src/hal_flash.c b/hw/mcu/native/src/hal_flash.c
index e3dde50..cdc36d5 100644
--- a/hw/mcu/native/src/hal_flash.c
+++ b/hw/mcu/native/src/hal_flash.c
@@ -94,6 +94,8 @@ static void
 flash_native_file_open(char *name)
 {
     int created = 0;
+    char tmpl[] = "/tmp/native_flash.XXXXXX";
+
     extern int ftruncate(int fd, off_t length);
 
     if (name) {
@@ -104,7 +106,6 @@ flash_native_file_open(char *name)
             created = 1;
         }
     } else {
-        char tmpl[] = "/tmp/native_flash.XXXXXX";
         file = mkstemp(tmpl);
         assert(file > 0);
         created = 1;
@@ -122,6 +123,11 @@ flash_native_file_open(char *name)
     if (created) {
         flash_native_erase(0, native_flash_dev.hf_size);
     }
+
+    /* If using a temporary file, unlink it immediately. */
+    if (name == NULL) {
+        remove(tmpl);
+    }
 }
 
 static void