Skip to content

Commit 337f64f

Browse files
committed
Merge pull request rlidwka#8 from PresenceInsights/sinopia_HashUpdate_fail
Sinopia hash update fail
2 parents 93b1eb4 + 63cd709 commit 337f64f

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

lib/local-couchdb.js

+32-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var nano = require('nano')({
2222
"requestDefaults" : { "agent" : myagent }
2323
}
2424
);
25-
var fs = require('fs')
2625

2726
function NanoError(code) {
2827
var err = Error(code)
@@ -120,24 +119,45 @@ module.exports.read_stream = function (name, stream, callback) {
120119
return stream;
121120
}
122121

122+
123123
module.exports.write_stream = function (name) {
124-
125-
var stream = MyStreams.UploadTarballStream()
124+
var stream = MyStreams.UploadTarballStream()
125+
126+
var _ended = 0
127+
stream.on('end', function() {
128+
_ended = 1
129+
})
126130

127-
fs.exists(name, function(exists) {
128-
if (exists) return stream.emit('error', FSError('EEXISTS'))
131+
var self = this;
132+
self.document_exists(name, function(err, headers){
133+
var opened = false
129134
var sinopia = nano.db.use('sinopia');
130-
131-
stream.emit('open')
132135
stream.pipe(
133-
sinopia.attachment.insert(name, name, null, 'application/x-compressed', {"docType" : "tarball"} )
136+
sinopia.attachment.insert(name, name, null, 'application/x-compressed', {"docType" : "tarball"})
134137
)
135-
136-
stream.emit('success')
137-
});
138-
return stream
138+
stream.done = function() {
139+
function onend() {
140+
stream.emit('success')
141+
}
142+
if (_ended) {
143+
onend()
144+
} else {
145+
stream.on('end', onend)
146+
}
147+
}
148+
stream.abort = function() {
149+
if (opened) {
150+
opened = false
151+
}
152+
}
153+
opened = true
154+
// re-emitting open because it's handled in storage.js
155+
stream.emit('open')
156+
});
157+
return stream
139158
}
140159

160+
141161
module.exports.delete_stream = function (name, callback) {
142162
var sinopia = nano.db.use('sinopia');
143163
sinopia.get(name, name, function(err, body){

0 commit comments

Comments
 (0)