OSError exception from host.mkdir() if existing entry and force=True

Bug #1361463 reported by Robert C Jennings
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Charm Helpers
Fix Released
Undecided
Jorge Niedbalski

Bug Description

mkdir will unlink the directory entry found for the path to be created if it exists and force=True, but it never creates the directory.

# touch /tmp/test

# cat > test.py << EOF
from charmhelpers.core import host
host.mkdir('/tmp/test')
host.mkdir('/tmp/test', force=True)
EOF

# python test.py

Well, that's not a real test, but the first call will log "INFO juju-log Making dir /etc/apache2/sites-available root:root 555" but do nothing because the path exists; this is a bit misleading.

The second call with force=True will unlink, not create the dir, and then attempt to chown the non-existent directory which throws and exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/lib/juju/agents/unit-ubuntu-repository-cache-0/charm/lib/charmhelpers/core/host.py", line 151, in mkdir
    os.chown(realpath, uid, gid)
OSError: [Errno 2] No such file or directory: '/tmp/test'

Related branches

Robert C Jennings (rcj)
Changed in charm-helpers:
assignee: nobody → Robert C Jennings (rcj)
status: New → In Progress
assignee: Robert C Jennings (rcj) → nobody
status: In Progress → New
summary: - host.mkdir() does not create directory if existing entry and force=True
+ OSError exception from host.mkdir() if existing entry and force=True
Changed in charm-helpers:
assignee: nobody → Jorge Niedbalski (niedbalski)
Changed in charm-helpers:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.