Skip to content

Commit

Permalink
Correct file cleanup, Python 2.4-compatible
Browse files Browse the repository at this point in the history
Amends e532cb1
  • Loading branch information
Dario Berzano committed May 16, 2014
1 parent e4ce819 commit 51ffae4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rpath/amiconfig/instancedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ def getUserData(self):
# Read user-data from cache if possible
user_data_cache = os.getenv("AMICONFIG_LOCAL_USER_DATA")
if user_data_cache is not None and user_data_cache[0] == '/':
f = None
try:
return open(user_data_cache).read()
f = open(user_data_cache)
return f.read()
except IOError, e:
pass
finally:
if f is not None:
f.close()

# Fall back to standard read
return self.read('user-data')
Expand Down

2 comments on commit 51ffae4

@dberzano
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jblomer: this should properly clean up the file in Python 2.4 when going out of the scope. There are other with statements around (in vaf-setup and elastiq-setup plugins) but they are meant to be processed with at least RHEL 6, so I would not worry.

@jblomer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Published.

Please sign in to comment.