# HG changeset patch
# User Hao Lian <hao@fogcreek.com>
# Date 2011-11-03 14:59:32
# Node ID db8b0ee74025f77c02b3cc9f183aca720f41a400
# Parent  ee112eb69d2aaed1ceb6922cb9c2cbc3fd893a0b

largefiles: ensure destination directory exists before findfile links to there

When (1) findfile links a largefile from the user cache to the store
and (2) the store directory doesn't exist yet, findfile errors out. A
simple call to util.makedirs fixes it.

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -110,7 +110,9 @@ def findfile(repo, hash):
         repo.ui.note(_('Found %s in store\n') % hash)
     elif inusercache(repo.ui, hash):
         repo.ui.note(_('Found %s in system cache\n') % hash)
-        link(usercachepath(repo.ui, hash), storepath(repo, hash))
+        path = storepath(repo, hash)
+        util.makedirs(os.path.dirname(path))
+        link(usercachepath(repo.ui, hash), path)
     else:
         return None
     return storepath(repo, hash)