Truncate docker-compose.yaml to zero bytes

Truncate docker-compose.yaml to zero bytes before writing the
updated config. Otherwise, if the existing config size is
more than the new config, trash is left behind.

Change-Id: I3d9628e53a4a100f333bab62fd775ab164179ec0
This commit is contained in:
Rabi Mishra
2016-01-13 10:51:38 +05:30
parent 810f40b148
commit 9a83954c13

View File

@@ -107,7 +107,8 @@ def write_compose_config(c):
proj_dir = os.path.join(DOCKER_COMPOSE_DIR, c['name'])
prepare_dir(proj_dir)
fn = os.path.join(proj_dir, 'docker-compose.yml')
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
'w') as f:
f.write(yaml_config.encode('utf-8'))