git ssb

30+

cel / git-ssb-web



Commit 65ac73cee50224c636df9b3bf0b66f7ba991a640

Fix serving packfiles over dumb http

cel committed on 10/18/2016, 1:21:35 AM
Parent: 3f3db7f933ef4c0d691241e3d7321484a300da28

Files changed

lib/repos/index.jschanged
lib/repos/index.jsView
@@ -1093,41 +1093,65 @@
10931093 }]),
10941094 pull(
10951095 repo.packs(),
10961096 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'
10981104 })
10991105 )
11001106 ]))
11011107 })
11021108 })
11031109 }
11041110
11051111 R.serveRepoPack = function (req, repo, name) {
1106- var m = name.match(/(.*)-(.*)\.(pack|idx)$/)
1112 + var m = name.match(/^pack-(.*)\.(pack|idx)$/)
11071113 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 + }
11081120
11091121 var self = this
11101122 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]
11211136
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 + }
11301154 })
1131- }
1155 + )
11321156 })
11331157 }

Built with git-ssb-web