That's an interesting point. I wonder what the TouchDB version does. I
would be inclined to add the DocID to the hash used to generate the key as
an easy fix.


On Tue, Apr 22, 2014 at 4:15 PM, Mike Rhodes <notifications@github.com>wrote:

> In src/main/java/com/cloudant/sync/datastore/AttachmentManager.java:
>
> > +        for (String attachmentName : attachmentNames) {
> > +            // first see if it exists
> > +            SavedAttachment a = (SavedAttachment) this.getAttachment(rev, attachmentName);
> > +            if (a == null) {
> > +                Log.w(LOG_TAG, "Could not find attachment to delete from database with filename = "+attachmentName+", sequence = "+rev.getSequence());
> > +                continue;
> > +            }
> > +            // get the file in blob store
> > +            File f = this.fileFromKey(a.key);
> > +            boolean rowDeleted = datastore.getSQLDatabase().delete("attachments", " filename = ? and sequence = ? ",
> > +                    new String[]{attachmentName, String.valueOf(rev.getSequence())}) == 1;
> > +            if (!rowDeleted) {
> > +                Log.w(LOG_TAG, "Could not delete attachment from database with filename = "+attachmentName+", sequence = "+rev.getSequence());
> > +            }
> > +            // delete attachments from blob store
> > +            boolean fileDeleted = f.delete();
>
> I'm not sure you can delete the file here. If an identical file was added
> at an attachment to another document, it'll have the same key in the blob
> store -- so you'd end up deleting a blob that was required by another
> document.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/cloudant/sync-android/pull/20/files#r11858237>
> .
>