Commit 65ac73cee50224c636df9b3bf0b66f7ba991a640
Fix serving packfiles over dumb http
cel committed on 10/18/2016, 1:21:35 AMParent: 3f3db7f933ef4c0d691241e3d7321484a300da28
Files changed
lib/repos/index.js | changed |
lib/repos/index.js | ||
---|---|---|
@@ -1093,41 +1093,65 @@ | ||
1093 | 1093 … | }]), |
1094 | 1094 … | pull( |
1095 | 1095 … | repo.packs(), |
1096 | 1096 … | pull.map(function (pack) { |
1097 | - return 'P ' + pack.packId + '-' + pack.idxId + '.pack\n' | |
1097 … | + var sha1 = pack.sha1 | |
1098 … | + if (!sha1) { | |
1099 … | + // make up a sha1 and hope git doesn't notice | |
1100 … | + var packId = new Buffer(pack.packId.substr(1, 44), 'base64') | |
1101 … | + sha1 = packId.slice(0, 20).toString('hex') | |
1102 … | + } | |
1103 … | + return 'P pack-' + sha1 + '.pack\n' | |
1098 | 1104 … | }) |
1099 | 1105 … | ) |
1100 | 1106 … | ])) |
1101 | 1107 … | }) |
1102 | 1108 … | }) |
1103 | 1109 … | } |
1104 | 1110 … | |
1105 | 1111 … | R.serveRepoPack = function (req, repo, name) { |
1106 | - var m = name.match(/(.*)-(.*)\.(pack|idx)$/) | |
1112 … | + var m = name.match(/^pack-(.*)\.(pack|idx)$/) | |
1107 | 1113 … | if (!m) return pull.once([400]) |
1114 … | + var hex; | |
1115 … | + try { | |
1116 … | + hex = new Buffer(m[1], 'hex') | |
1117 … | + } catch(e) { | |
1118 … | + return pull.once([400]) | |
1119 … | + } | |
1108 | 1120 … | |
1109 | 1121 … | var self = this |
1110 | 1122 … | return u.readNext(function (cb) { |
1111 | - if (m[3] === 'pack') { | |
1112 | - var packId = m[1] | |
1113 | - if (!ssbRef.isBlobId(packId)) return cb(null, pull.once([400])) | |
1114 | - repo.getPackfile(packId, function (err, read) { | |
1115 | - if (err) return cb(err) | |
1116 | - cb(null, pull(read, | |
1117 | - self.web.serveRaw(null, 'application/x-git-packed-objects') | |
1118 | - )) | |
1119 | - }) | |
1120 | - } | |
1123 … | + pull( | |
1124 … | + repo.packs(), | |
1125 … | + pull.filter(function (pack) { | |
1126 … | + var sha1 = pack.sha1 | |
1127 … | + ? new Buffer(pack.sha1, 'hex') | |
1128 … | + : new Buffer(pack.packId.substr(1, 44), 'base64').slice(0, 20) | |
1129 … | + return sha1.equals(hex) | |
1130 … | + }), | |
1131 … | + pull.take(1), | |
1132 … | + pull.collect(function (err, packs) { | |
1133 … | + if (err) return console.error(err), cb(null, pull.once([500])) | |
1134 … | + if (packs.length < 1) return cb(null, pull.once([404])) | |
1135 … | + var pack = packs[0] | |
1121 | 1136 … | |
1122 | - if (m[3] === 'idx') { | |
1123 | - var idxId = m[2] | |
1124 | - if (!ssbRef.isBlobId(idxId)) return cb(null, pull.once([400])) | |
1125 | - repo.getPackIndex(idxId, function (err, read) { | |
1126 | - if (err) return cb(err) | |
1127 | - cb(null, pull(read, | |
1128 | - self.web.serveRaw(null, 'application/x-git-packed-objects-toc') | |
1129 | - )) | |
1137 … | + if (m[2] === 'pack') { | |
1138 … | + repo.getPackfile(pack.packId, function (err, read) { | |
1139 … | + if (err) return cb(err) | |
1140 … | + cb(null, pull(read, | |
1141 … | + self.web.serveRaw(null, 'application/x-git-packed-objects') | |
1142 … | + )) | |
1143 … | + }) | |
1144 … | + } | |
1145 … | + | |
1146 … | + if (m[2] === 'idx') { | |
1147 … | + repo.getPackIndex(pack.idxId, function (err, read) { | |
1148 … | + if (err) return cb(err) | |
1149 … | + cb(null, pull(read, | |
1150 … | + self.web.serveRaw(null, 'application/x-git-packed-objects-toc') | |
1151 … | + )) | |
1152 … | + }) | |
1153 … | + } | |
1130 | 1154 … | }) |
1131 | - } | |
1155 … | + ) | |
1132 | 1156 … | }) |
1133 | 1157 … | } |
Built with git-ssb-web