aboutsummaryrefslogtreecommitdiff
path: root/bdep/new.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bdep/new.cxx')
-rw-r--r--bdep/new.cxx8
1 files changed, 7 insertions, 1 deletions
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 753b8f3..2c954fc 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -3220,10 +3220,16 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
bool e (exists (f));
try
{
+ // Note: add an extra newline if appending to an existing file. While
+ // this will normally result in an extra blank line between entries
+ // which we don't really need, it will also make sure we don't generate
+ // invalid file if there is no newline at the end of file (which can
+ // happen if the file was edited manually).
+ //
ofdstream os (f, (fdopen_mode::out |
fdopen_mode::create |
fdopen_mode::append));
- os << (e ? ":" : ": 1") << '\n'
+ os << (e ? "\n:" : ": 1") << '\n'
<< "location: " << pkg->posix_representation () << '\n';
os.close ();
}