Permalink
Browse files

[bugfix] Fixes for determining when permissions should be preserved d…

…uring copies

or not
  • Loading branch information...
1 parent 7b18eff commit 83357ef67497ebdb87141478c4672e5b107b60e1 @adamretter adamretter committed Jan 26, 2014
@@ -292,7 +292,7 @@ private void before(DBBroker broker, Txn transaction, DocumentImpl document, boo
vDoc = vCollection.getDocument(broker, binUri);
} else {
vDoc = new DocumentImpl(broker.getBrokerPool(), vCollection, XmldbURI.createInternal(vFileName));
- vDoc.copyOf(document);
+ vDoc.copyOf(document, true);
vDoc.copyChildren(document);
}
@@ -1677,7 +1677,7 @@ private IndexInfo validateXMLResourceInternal(final Txn transaction, final DBBro
} else {
//TODO : use a more elaborated method ? No triggers...
broker.removeXMLResource(transaction, oldDoc, false);
- oldDoc.copyOf(document);
+ oldDoc.copyOf(document, true);
indexer.setDocumentObject(oldDoc);
//old has become new at this point
document = oldDoc;
@@ -312,8 +312,13 @@ public DocumentMetadata getMetadata() {
* This is called by {@link Collection} when replacing a document.
*
* @param other a <code>DocumentImpl</code> value
+ * @param preserve Cause copyOf to preserve the following attributes of
+ * each source file in the copy: modification time,
+ * access time, file mode, user ID, and group ID,
+ * as allowed by permissions and Access Control
+ * Lists (ACLs)
*/
- public void copyOf(DocumentImpl other) {
+ public void copyOf(final DocumentImpl other, final boolean preserve) {
childAddress = null;
children = 0;
@@ -326,16 +331,21 @@ public void copyOf(DocumentImpl other) {
//copy metadata
metadata.copyOf(other.getMetadata());
- //update timestamp
- final long timestamp = System.currentTimeMillis();
- metadata.setCreated(timestamp);
- metadata.setLastModified(timestamp);
+ if(preserve) {
+ //copy permission
+ permissions = ((UnixStylePermission)other.permissions).copy();
+ //created and last modified are done by metadata.copyOf
+ //metadata.setCreated(other.getMetadata().getCreated());
+ //metadata.setLastModified(other.getMetadata().getLastModified());
+ } else {
+ //update timestamp
+ final long timestamp = System.currentTimeMillis();
+ metadata.setCreated(timestamp);
+ metadata.setLastModified(timestamp);
+ }
// reset pageCount: will be updated during storage
metadata.setPageCount(0);
-
- //copy permission
- permissions = ((UnixStylePermission)other.permissions).copy();
}
/**
@@ -1130,7 +1130,7 @@ private Collection doCopyCollection(final Txn transaction, final Collection coll
if (child.getResourceType() == DocumentImpl.XML_FILE) {
//TODO : put a lock on newDoc ?
final DocumentImpl newDoc = new DocumentImpl(pool, destCollection, child.getFileURI());
- newDoc.copyOf(child);
+ newDoc.copyOf(child, false);
newDoc.setDocId(getNextResourceId(transaction, destination));
copyXMLResource(transaction, child, newDoc);
storeXMLResource(transaction, newDoc);
@@ -1139,7 +1139,7 @@ private Collection doCopyCollection(final Txn transaction, final Collection coll
createdDoc = newDoc;
} else {
final BinaryDocument newDoc = new BinaryDocument(pool, destCollection, child.getFileURI());
- newDoc.copyOf(child);
+ newDoc.copyOf(child, false);
newDoc.setDocId(getNextResourceId(transaction, destination));
InputStream is = null;
@@ -2522,9 +2522,8 @@ public void copyResource(Txn transaction, DocumentImpl doc, Collection destinati
}
} else {
DocumentImpl newDoc = new DocumentImpl(pool, destination, newName);
- newDoc.copyOf(doc);
+ newDoc.copyOf(doc, false);
newDoc.setDocId(getNextResourceId(transaction, destination));
- //newDoc.setPermissions(doc.getPermissions());
newDoc.getUpdateLock().acquire(Lock.WRITE_LOCK);
try {
copyXMLResource(transaction, doc, newDoc);
@@ -3019,7 +3018,7 @@ public Object start() {
}.run();
// create a copy of the old doc to copy the nodes into it
final DocumentImpl tempDoc = new DocumentImpl(pool, doc.getCollection(), doc.getFileURI());
- tempDoc.copyOf(doc);
+ tempDoc.copyOf(doc, true);
tempDoc.setDocId(doc.getDocId());
indexController.setDocument(doc, StreamListener.STORE);
final StreamListener listener = indexController.getStreamListener();
@@ -53,7 +53,7 @@ public void copyOf_calls_getMetadata() {
other.setMetadata(otherMetadata);
//actions
- doc.copyOf(other);
+ doc.copyOf(other, false);
verify(mockBrokerPool, mockDatabase, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
@@ -91,7 +91,7 @@ public void copyOf_calls_metadata_copyOf() {
other.setMetadata(otherMetadata);
//actions
- doc.copyOf(other);
+ doc.copyOf(other, false);
verify(mockBrokerPool, mockDatabase, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
@@ -131,7 +131,7 @@ public void copyOf_updates_metadata_created_and_lastModified() {
other.setMetadata(otherMetadata);
//actions
- doc.copyOf(other);
+ doc.copyOf(other, false);
verify(mockBrokerPool, mockDatabase, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
Oops, something went wrong. Retry.

0 comments on commit 83357ef

Please sign in to comment.