def putlfile(repo, proto, sha): '''Put a largefile into a repository's local store and into the user cache.''' proto.redirect() path = lfutil.storepath(repo, sha) util.makedirs(os.path.dirname(path)) tmpfp = util.atomictempfile(path, createmode=repo.store.createmode) try: try: proto.getfile(tmpfp) tmpfp._fp.seek(0) if sha != lfutil.hexsha1(tmpfp._fp): raise IOError(0, _('largefile contents do not match hash')) tmpfp.close() lfutil.linktousercache(repo, sha) except IOError, e: repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') % (sha, e.strerror)) return wireproto.pushres(1) finally: tmpfp.discard() return wireproto.pushres(0)
def putlfile(repo, proto, sha): '''Server command for putting a largefile into a repository's local store and into the user cache.''' proto.redirect() path = lfutil.storepath(repo, sha) util.makedirs(os.path.dirname(path)) tmpfp = util.atomictempfile(path, createmode=repo.store.createmode) try: proto.getfile(tmpfp) tmpfp._fp.seek(0) if sha != lfutil.hexsha1(tmpfp._fp): raise IOError(0, _('largefile contents do not match hash')) tmpfp.close() lfutil.linktousercache(repo, sha) except IOError as e: repo.ui.warn( _('largefiles: failed to put %s into store: %s\n') % (sha, e.strerror)) return wireproto.pushres(1) finally: tmpfp.discard() return wireproto.pushres(0)
def statlfile(repo, proto, sha): '''Return '2\n' if the largefile is missing, '1\n' if it has a mismatched checksum, or '0\n' if it is in good condition''' filename = lfutil.findfile(repo, sha) if not filename: return '2\n' fd = None try: fd = open(filename, 'rb') return lfutil.hexsha1(fd) == sha and '0\n' or '1\n' finally: if fd: fd.close()
def statlfile(repo, proto, sha): """Return '2\n' if the largefile is missing, '1\n' if it has a mismatched checksum, or '0\n' if it is in good condition""" filename = lfutil.findfile(repo, sha) if not filename: return "2\n" fd = None try: fd = open(filename, "rb") return lfutil.hexsha1(fd) == sha and "0\n" or "1\n" finally: if fd: fd.close()
def putlfile(repo, proto, sha): '''Put a largefile into a repository's local store and into the user cache.''' proto.redirect() fd, tmpname = lfutil.mkstemp(repo, prefix='hg-putlfile') tmpfp = os.fdopen(fd, 'wb+') try: try: proto.getfile(tmpfp) tmpfp.seek(0) if sha != lfutil.hexsha1(tmpfp): return wireproto.pushres(1) tmpfp.close() lfutil.copytostoreabsolute(repo, tmpname, sha) except IOError, e: repo.ui.warn(_('largefiles: failed to put %s (%s) into store: %s') % (sha, tmpname, e.strerror)) return wireproto.pushres(1) finally: tmpfp.close() os.unlink(tmpname) return wireproto.pushres(0)