diff options
Diffstat (limited to 'xmake/core/base/io.lua')
| -rw-r--r-- | xmake/core/base/io.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua index 3b04b9fdd..71c6cc5b8 100644 --- a/xmake/core/base/io.lua +++ b/xmake/core/base/io.lua @@ -27,6 +27,9 @@ local io = io or {} local path = require("base/path") local utils = require("base/utils") +-- save original open +io._open = io._open or io.open + -- save object with the level function io._save_with_level(file, object, level) @@ -137,6 +140,28 @@ function io.writall(filepath, data) return true end +-- replace the original open interface +function io.open(filepath, mode) + + -- check + assert(filepath) + + -- write file? + if mode == "w" then + + -- get the file directory + local dir = path.directory(filepath) + + -- ensure the file directory + if not os.isdir(dir) then + os.mkdir(dir) + end + end + + -- open it + return io._open(filepath, mode) +end + -- save object the the given filepath function io.save(filepath, object) |
