comparison hgext/largefiles/lfutil.py @ 18998:d035c3902111

largefiles: refactoring - create destination dir in lfutil.link
author Mads Kiilerich <madski@unity3d.com>
date Mon, 15 Apr 2013 23:32:33 +0200
parents 9717a326d270
children c1b5f9c4d989
comparison
equal deleted inserted replaced
18997:4cf09a1bf5b2 18998:d035c3902111
37 if lfsize is None: 37 if lfsize is None:
38 raise util.Abort(_('minimum size for largefiles must be specified')) 38 raise util.Abort(_('minimum size for largefiles must be specified'))
39 return lfsize 39 return lfsize
40 40
41 def link(src, dest): 41 def link(src, dest):
42 util.makedirs(os.path.dirname(dest))
42 try: 43 try:
43 util.oslink(src, dest) 44 util.oslink(src, dest)
44 except OSError: 45 except OSError:
45 # if hardlinks fail, fallback on atomic copy 46 # if hardlinks fail, fallback on atomic copy
46 dst = util.atomictempfile(dest) 47 dst = util.atomictempfile(dest)
84 repo.ui.note(_('found %s in store\n') % hash) 85 repo.ui.note(_('found %s in store\n') % hash)
85 return storepath(repo, hash) 86 return storepath(repo, hash)
86 elif inusercache(repo.ui, hash): 87 elif inusercache(repo.ui, hash):
87 repo.ui.note(_('found %s in system cache\n') % hash) 88 repo.ui.note(_('found %s in system cache\n') % hash)
88 path = storepath(repo, hash) 89 path = storepath(repo, hash)
89 util.makedirs(os.path.dirname(path))
90 link(usercachepath(repo.ui, hash), path) 90 link(usercachepath(repo.ui, hash), path)
91 return path 91 return path
92 return None 92 return None
93 93
94 class largefilesdirstate(dirstate.dirstate): 94 class largefilesdirstate(dirstate.dirstate):
201 realfile = splitstandin(filename) 201 realfile = splitstandin(filename)
202 copytostore(repo, ctx.node(), realfile) 202 copytostore(repo, ctx.node(), realfile)
203 203
204 204
205 def copytostoreabsolute(repo, file, hash): 205 def copytostoreabsolute(repo, file, hash):
206 util.makedirs(os.path.dirname(storepath(repo, hash)))
207 if inusercache(repo.ui, hash): 206 if inusercache(repo.ui, hash):
208 link(usercachepath(repo.ui, hash), storepath(repo, hash)) 207 link(usercachepath(repo.ui, hash), storepath(repo, hash))
209 elif not getattr(repo, "_isconverting", False): 208 elif not getattr(repo, "_isconverting", False):
209 util.makedirs(os.path.dirname(storepath(repo, hash)))
210 dst = util.atomictempfile(storepath(repo, hash), 210 dst = util.atomictempfile(storepath(repo, hash),
211 createmode=repo.store.createmode) 211 createmode=repo.store.createmode)
212 for chunk in util.filechunkiter(open(file, 'rb')): 212 for chunk in util.filechunkiter(open(file, 'rb')):
213 dst.write(chunk) 213 dst.write(chunk)
214 dst.close() 214 dst.close()
215 linktousercache(repo, hash) 215 linktousercache(repo, hash)
216 216
217 def linktousercache(repo, hash): 217 def linktousercache(repo, hash):
218 path = usercachepath(repo.ui, hash) 218 path = usercachepath(repo.ui, hash)
219 if path: 219 if path:
220 util.makedirs(os.path.dirname(path))
221 link(storepath(repo, hash), path) 220 link(storepath(repo, hash), path)
222 221
223 def getstandinmatcher(repo, pats=[], opts={}): 222 def getstandinmatcher(repo, pats=[], opts={}):
224 '''Return a match object that applies pats to the standin directory''' 223 '''Return a match object that applies pats to the standin directory'''
225 standindir = repo.wjoin(shortname) 224 standindir = repo.wjoin(shortname)