Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurélien Vermylen
jio
Commits
12f16a47
Commit
12f16a47
authored
Jan 08, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix remove attachment
parent
f75085c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
144 additions
and
47 deletions
+144
-47
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+137
-42
test/jiotests.js
test/jiotests.js
+7
-5
No files found.
src/jio.storage/revisionstorage.js
View file @
12f16a47
...
...
@@ -272,11 +272,13 @@ jIO.addStorageType('revision', function (spec, my) {
"
rev
"
:
next_rev
.
join
(
'
-
'
),
"
status
"
:
flag
});
selected_node
.
children
.
unshift
({
"
rev
"
:
next_rev
.
join
(
'
-
'
),
"
status
"
:
flag
,
"
children
"
:
[]
});
return
revs_info
;
};
...
...
@@ -648,8 +650,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command
*/
that
.
remove
=
function
(
command
)
{
var
f
=
{},
del_rev
,
option
,
i
,
revision_found
=
false
,
revision_count
=
0
,
correct_revision
;
var
f
=
{},
del_rev
,
option
,
new_doc
,
revs_info
,
new_id
;
option
=
command
.
cloneOption
();
if
(
option
[
"
max_retry
"
]
===
0
)
{
option
[
"
max_retry
"
]
=
3
;
...
...
@@ -658,31 +659,126 @@ jIO.addStorageType('revision', function (spec, my) {
f
.
removeDocument
=
function
(
docid
,
doctree
)
{
if
(
command
.
getOption
(
"
keep_revision_history
"
)
!==
true
)
{
that
.
addJob
(
"
remove
"
,
priv
.
substorage
,
docid
,
option
,
function
(
response
)
{
if
(
typeof
command
.
getAttachmentId
()
===
undefined
){
priv
.
postToDocumentTree
(
doctree
,
command
.
getDoc
(),
true
if
(
command
.
getAttachmentId
()
===
undefined
){
// update tree
priv
.
postToDocumentTree
(
doctree
,
command
.
getDoc
(),
true
);
// remove revision
that
.
addJob
(
"
remove
"
,
priv
.
substorage
,
docid
,
option
,
function
(
response
)
{
// put tree
that
.
addJob
(
"
put
"
,
priv
.
substorage
,
doctree
,
command
.
cloneOption
(),
function
(
response
)
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
docid
,
"
rev
"
:
revs_info
[
0
].
rev
});
},
function
(
err
){
that
.
error
({
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
error
"
:
"
conflict
"
,
"
message
"
:
"
Document update conflict.
"
,
"
reason
"
:
"
Cannot update document tree
"
});
return
;
}
);
}
else
{
priv
.
postToDocumentTree
(
doctree
,
command
.
getDoc
());
},
function
(
err
)
{
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
File not found
"
,
"
reason
"
:
"
Document was not found
"
});
return
;
}
},
function
(
err
)
{
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
File not found
"
,
"
reason
"
:
"
Document was not found
"
});
return
;
}
);
);
}
else
{
// get previsous document
that
.
addJob
(
"
get
"
,
priv
.
substorage
,
command
.
getDocId
()
+
"
.
"
+
del_rev
,
option
,
function
(
response
)
{
// update tree
revs_info
=
priv
.
postToDocumentTree
(
doctree
,
command
.
getDoc
());
new_doc
=
response
;
delete
new_doc
.
_attachments
;
new_doc
.
_id
=
new_doc
.
_id
+
"
.
"
+
revs_info
[
0
].
rev
;
// post new document version
that
.
addJob
(
"
post
"
,
priv
.
substorage
,
new_doc
,
command
.
cloneOption
(),
function
(
response
)
{
// put tree
doctree
.
_id
=
command
.
getDocId
()
+
priv
.
doctree_suffix
;
that
.
addJob
(
"
put
"
,
priv
.
substorage
,
doctree
,
command
.
cloneOption
(),
function
(
response
)
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
new_doc
.
_id
,
"
rev
"
:
revs_info
[
0
].
rev
});
},
function
(
err
)
{
err
.
message
=
"
Cannot save document revision tree
"
;
that
.
error
(
err
);
}
);
},
function
(
err
){
that
.
error
({
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
error
"
:
"
conflict
"
,
"
message
"
:
"
Document update conflict.
"
,
"
reason
"
:
"
Cannot update document
"
});
return
;
}
);
},
function
(
err
)
{
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
File not found
"
,
"
reason
"
:
"
Document was not found
"
});
return
;
}
);
}
}
else
{
// keep history = update document tree only
}
...
...
@@ -722,25 +818,24 @@ jIO.addStorageType('revision', function (spec, my) {
return
;
}
else
{
// revision provided
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
){
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
+
"
/
"
+
command
.
getAttachmentId
(),
response
);
}
else
{
// loop leaves
if
(
priv
.
isRevisionALeaf
(
del_rev
,
priv
.
getLeavesFromDocumentTree
(
response
))
===
true
){
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
,
response
);
if
(
priv
.
isRevisionALeaf
(
response
,
del_rev
)
===
true
){
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
){
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
+
"
/
"
+
command
.
getAttachmentId
(),
response
);
}
else
{
that
.
error
({
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
error
"
:
"
conflict
"
,
"
message
"
:
"
Document update conflict.
"
,
"
reason
"
:
"
Trying to remove non-latest revision
"
});
return
;
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
,
response
);
}
}
else
{
that
.
error
({
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
error
"
:
"
conflict
"
,
"
message
"
:
"
Document update conflict.
"
,
"
reason
"
:
"
Trying to remove non-latest revision
"
});
return
;
}
}
},
...
...
test/jiotests.js
View file @
12f16a47
...
...
@@ -1424,7 +1424,8 @@ test ("Remove", function(){
o
.
rev
=
"
3-
"
+
generateRevisionHash
(
o
.
doc_myremove1
,
o
.
revisions
);
// 4. remove existing attachment with revision
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove1
"
,
"
rev
"
:
o
.
rev
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove1.
"
+
o
.
rev
,
"
rev
"
:
o
.
rev
},
"
Remove existing attachment (revision)
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1/remove2
"
,
"
_rev
"
:
o
.
old_rev
},
o
.
f
);
o
.
tick
(
o
);
...
...
@@ -1452,8 +1453,8 @@ test ("Remove", function(){
// 7. check if document is updated
deepEqual
(
localstorage
.
getItem
(
"
jio/localstorage/urevrem/arevrem/remove1.
"
+
o
.
rev
),
{
"
_id
"
:
"
remove1.
"
+
o
.
rev
},
"
Check document
"
);
),
{
"
_id
"
:
"
remove1.
"
+
o
.
rev
,
"
title
"
:
"
myRemove1
"
},
"
Check document
"
);
/*
// add another attachment
o.attmt_myremove2 = {
"remove3": {
...
...
@@ -1540,11 +1541,11 @@ test ("Remove", function(){
o.spy (o,"status", 409, "409 - Removing document (no revision)");
o.jio.remove({"_id":"remove1"}, o.f);
o.tick(o);
*/
o
.
jio
.
stop
();
});
/*
module ( "Jio Revision Storage + Local Storage" );
test ("Scenario", function(){
...
...
@@ -1680,6 +1681,7 @@ test ("Scenario", function(){
ok ( o.jio, "Close application");
});
*/
/*
module ('Jio DAVStorage');
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment