Adds fields for the file/folder NodeRef, and linked NodeRef for a link node.
+ *
+ * @author gkspencer
+ */
+public class ContentFileInfo extends FileInfo {
+
+ // Version id
+
+ private static final long serialVersionUID = 2518699645372408663L;
+
+ // File/folder node
+
+ private NodeRef m_nodeRef;
+
+ // Linked node
+
+ private NodeRef m_linkRef;
+
+ /**
+ * Return the file/folder node
+ *
+ * @return NodeRef
+ */
+ public final NodeRef getNodeRef()
+ {
+ return m_nodeRef;
+ }
+
+ /**
+ * Check if this is a link node
+ *
+ * @return boolean
+ */
+ public final boolean isLinkNode()
+ {
+ return m_linkRef != null ? true : false;
+ }
+
+ /**
+ * Return the link node, or null if this is not a link
+ *
+ * @return NodeRef
+ */
+ public final NodeRef getLinkNodeRef()
+ {
+ return m_linkRef;
+ }
+
+ /**
+ * Set the node for this file/folder
+ *
+ * @param node NodeRef
+ */
+ public final void setNodeRef(NodeRef node)
+ {
+ m_nodeRef = node;
+ }
+
+ /**
+ * Set the link node
+ *
+ * @param link NodeRef
+ */
+ public final void setLinkNodeRef(NodeRef link)
+ {
+ m_linkRef = link;
+ }
+}
diff --git a/source/java/org/alfresco/filesys/smb/server/repo/ContentIOControlHandler.java b/source/java/org/alfresco/filesys/smb/server/repo/ContentIOControlHandler.java
index fd8495cd57..90f1df8089 100644
--- a/source/java/org/alfresco/filesys/smb/server/repo/ContentIOControlHandler.java
+++ b/source/java/org/alfresco/filesys/smb/server/repo/ContentIOControlHandler.java
@@ -175,6 +175,20 @@ public class ContentIOControlHandler implements IOControlHandler
int devType = NTIOCtl.getDeviceType(ctrlCode);
int ioFunc = NTIOCtl.getFunctionCode(ctrlCode);
+ // Check for I/O controls that require a success status
+
+ if ( devType == NTIOCtl.DeviceFileSystem)
+ {
+ // I/O control requests that require a success status
+ //
+ // Create or get object id
+
+ if ( ioFunc == NTIOCtl.FsCtlCreateOrGetObjectId)
+ return null;
+ }
+
+ // Check if the I/O control looks like a custom I/O control request
+
if ( devType != NTIOCtl.DeviceFileSystem || dataBuf == null)
throw new IOControlNotImplementedException();
@@ -260,7 +274,7 @@ public class ContentIOControlHandler implements IOControlHandler
retBuffer = procRunAction(sess, tree, dataBuf, folderNode, netFile);
break;
-
+
// Unknown I/O control code
default:
diff --git a/source/java/org/alfresco/filesys/smb/server/repo/ContentNetworkFile.java b/source/java/org/alfresco/filesys/smb/server/repo/ContentNetworkFile.java
index 1ee735c41d..5a9fee53e6 100644
--- a/source/java/org/alfresco/filesys/smb/server/repo/ContentNetworkFile.java
+++ b/source/java/org/alfresco/filesys/smb/server/repo/ContentNetworkFile.java
@@ -50,14 +50,13 @@ import org.apache.commons.logging.LogFactory;
*
* @author Derek Hulley
*/
-public class ContentNetworkFile extends NetworkFile
+public class ContentNetworkFile extends NodeRefNetworkFile
{
private static final Log logger = LogFactory.getLog(ContentNetworkFile.class);
private TransactionService transactionService;
private NodeService nodeService;
private ContentService contentService;
- private NodeRef nodeRef;
// File channel to file content
@@ -175,12 +174,11 @@ public class ContentNetworkFile extends NetworkFile
NodeRef nodeRef,
String name)
{
- super(name);
+ super(name, nodeRef);
setFullName(name);
this.transactionService = transactionService;
this.nodeService = nodeService;
this.contentService = contentService;
- this.nodeRef = nodeRef;
}
/**
@@ -193,7 +191,7 @@ public class ContentNetworkFile extends NetworkFile
StringBuilder str = new StringBuilder();
str.append( "[");
- str.append( nodeRef.getId());
+ str.append( getNodeRef().getId());
str.append( ",channel=");
str.append( channel);
if ( channel != null)
@@ -205,14 +203,6 @@ public class ContentNetworkFile extends NetworkFile
return str.toString();
}
- /**
- * @return Returns the node reference representing this file
- */
- public NodeRef getNodeRef()
- {
- return nodeRef;
- }
-
/**
* @return Returns true if the channel should be writable
*
@@ -304,7 +294,7 @@ public class ContentNetworkFile extends NetworkFile
{
// Get a writeable channel to the content
- content = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, false);
+ content = contentService.getWriter( getNodeRef(), ContentModel.PROP_CONTENT, false);
// Indicate that we have a writable channel to the file
@@ -318,14 +308,14 @@ public class ContentNetworkFile extends NetworkFile
{
// Get a read-only channel to the content
- content = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
+ content = contentService.getReader( getNodeRef(), ContentModel.PROP_CONTENT);
// Ensure that the content we are going to read is valid
content = FileContentReader.getSafeContentReader(
(ContentReader) content,
I18NUtil.getMessage(FileContentReader.MSG_MISSING_CONTENT),
- nodeRef, content);
+ getNodeRef(), content);
// Indicate that we only have a read-only channel to the data
@@ -372,7 +362,7 @@ public class ContentNetworkFile extends NetworkFile
// Update node properties
ContentData contentData = content.getContentData();
- nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, contentData);
+ nodeService.setProperty( getNodeRef(), ContentModel.PROP_CONTENT, contentData);
}
else
{
diff --git a/source/java/org/alfresco/filesys/smb/server/repo/ContentSearchContext.java b/source/java/org/alfresco/filesys/smb/server/repo/ContentSearchContext.java
index 4a8898dbc2..2dbf99d8ac 100644
--- a/source/java/org/alfresco/filesys/smb/server/repo/ContentSearchContext.java
+++ b/source/java/org/alfresco/filesys/smb/server/repo/ContentSearchContext.java
@@ -19,6 +19,7 @@ package org.alfresco.filesys.smb.server.repo;
import java.io.FileNotFoundException;
import java.util.List;
+import org.alfresco.filesys.server.filesys.FileAttribute;
import org.alfresco.filesys.server.filesys.FileInfo;
import org.alfresco.filesys.server.filesys.FileName;
import org.alfresco.filesys.server.filesys.SearchContext;
@@ -37,8 +38,18 @@ import org.apache.commons.logging.LogFactory;
*/
public class ContentSearchContext extends SearchContext
{
+ // Debug logging
+
private static final Log logger = LogFactory.getLog(ContentSearchContext.class);
+ // Constants
+ //
+ // Link file size, actual size will be set if/when the link is opened
+
+ public final static int LinkFileSize = 512;
+
+ // List of nodes returned from the folder search
+
private CifsHelper cifsHelper;
private List In memory network file implementation that uses a memory buffer for the file data.
+ *
+ * @author gkspencer
+ */
+public class LinkMemoryNetworkFile extends NodeRefNetworkFile
+{
+ // Current file position
+
+ private long m_filePos;
+
+ // File data
+
+ private byte[] m_data;
+
+ /**
+ * Class constructor.
+ *
+ * @param name String
+ * @param localPath String
+ * @param finfo FileInfo
+ * @param nodeRef NodeRef
+ */
+ public LinkMemoryNetworkFile(String name, byte[] data, FileInfo finfo, NodeRef nodeRef)
+ {
+ super( name, nodeRef);
+
+ // Set the file data
+
+ m_data = data;
+ if ( m_data == null)
+ m_data = new byte[0];
+
+ // Set the file size
+
+ setFileSize( m_data.length);
+
+ // Set the creation and modification date/times
+
+ setModifyDate( finfo.getModifyDateTime());
+ setCreationDate( finfo.getCreationDateTime());
+
+ // Set the file id and relative path
+
+ if ( finfo.getPath() != null)
+ {
+ setFileId( finfo.getPath().hashCode());
+ setFullName( finfo.getPath());
+ }
+ }
+
+ /**
+ * Close the network file.
+ */
+ public void closeFile() throws java.io.IOException
+ {
+ // Nothing to do
+ }
+
+ /**
+ * Return the current file position.
+ *
+ * @return long
+ */
+ public long currentPosition()
+ {
+ return m_filePos;
+ }
+
+ /**
+ * Flush the file.
+ *
+ * @exception IOException
+ */
+ public void flushFile() throws IOException
+ {
+ // Nothing to do
+ }
+
+ /**
+ * Determine if the end of file has been reached.
+ *
+ * @return boolean
+ */
+ public boolean isEndOfFile() throws java.io.IOException
+ {
+ // Check if we reached end of file
+
+ if ( m_filePos == m_data.length)
+ return true;
+ return false;
+ }
+
+ /**
+ * Open the file.
+ *
+ * @param createFlag boolean
+ * @exception IOException
+ */
+ public void openFile(boolean createFlag) throws java.io.IOException
+ {
+ // Indicate that the file is open
+
+ setClosed(false);
+ }
+
+ /**
+ * Read from the file.
+ *
+ * @param buf byte[]
+ * @param len int
+ * @param pos int
+ * @param fileOff long
+ * @return Length of data read.
+ * @exception IOException
+ */
+ public int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException
+ {
+ // Check if the read is within the file data range
+
+ long fileLen = (long) m_data.length;
+
+ if ( fileOff >= fileLen)
+ return 0;
+
+ // Calculate the actual read length
+
+ if (( fileOff + len) > fileLen)
+ len = (int) ( fileLen - fileOff);
+
+ // Copy the data to the user buffer
+
+ System.arraycopy( m_data, (int) fileOff, buf, pos, len);
+
+ // Update the current file position
+
+ m_filePos = fileOff + len;
+
+ // Return the actual length of data read
+
+ return len;
+ }
+
+ /**
+ * Seek to the specified file position.
+ *
+ * @param pos long
+ * @param typ int
+ * @return long
+ * @exception IOException
+ */
+ public long seekFile(long pos, int typ) throws IOException
+ {
+ // Seek to the required file position
+
+ switch (typ)
+ {
+ // From start of file
+
+ case SeekType.StartOfFile:
+ if (currentPosition() != pos)
+ m_filePos = pos;
+ break;
+
+ // From current position
+
+ case SeekType.CurrentPos:
+ m_filePos += pos;
+ break;
+
+ // From end of file
+
+ case SeekType.EndOfFile:
+ m_filePos += pos;
+ if ( m_filePos < 0)
+ m_filePos = 0L;
+ break;
+ }
+
+ // Return the new file position
+
+ return currentPosition();
+ }
+
+ /**
+ * Truncate the file
+ *
+ * @param siz long
+ * @exception IOException
+ */
+ public void truncateFile(long siz) throws IOException
+ {
+ // Allow the truncate, do not alter the pseduo file data
+ }
+
+ /**
+ * Write a block of data to the file.
+ *
+ * @param buf byte[]
+ * @param len int
+ * @exception IOException
+ */
+ public void writeFile(byte[] buf, int len, int pos) throws java.io.IOException
+ {
+ // Allow the write, just do not do anything
+ }
+
+ /**
+ * Write a block of data to the file.
+ *
+ * @param buf byte[]
+ * @param len int
+ * @param pos int
+ * @param offset long
+ * @exception IOException
+ */
+ public void writeFile(byte[] buf, int len, int pos, long offset) throws java.io.IOException
+ {
+ // Allow the write, just do not do anything
+ }
+}
diff --git a/source/java/org/alfresco/filesys/smb/server/repo/NodeRefNetworkFile.java b/source/java/org/alfresco/filesys/smb/server/repo/NodeRefNetworkFile.java
new file mode 100644
index 0000000000..f9995494da
--- /dev/null
+++ b/source/java/org/alfresco/filesys/smb/server/repo/NodeRefNetworkFile.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2005-2006 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.filesys.smb.server.repo;
+
+import org.alfresco.filesys.server.filesys.NetworkFile;
+import org.alfresco.service.cmr.repository.NodeRef;
+
+/**
+ * NodeRef Based Network File Class
+ *
+ * @author gkspencer
+ */
+public abstract class NodeRefNetworkFile extends NetworkFile {
+
+ // Associated node ref
+
+ protected NodeRef m_nodeRef;
+
+ /**
+ * Create a network file object with the specified file/directory name.
+ *
+ * @param name File name string.
+ */
+ public NodeRefNetworkFile(String name)
+ {
+ super( name);
+ }
+
+ /**
+ * Create a network file object with the specified file/directory name.
+ *
+ * @param name File name string.
+ * @param node NodeRef
+ */
+ public NodeRefNetworkFile(String name, NodeRef node)
+ {
+ super( name);
+
+ m_nodeRef = node;
+ }
+
+ /**
+ * Return the node ref
+ *
+ * @return NodeRef
+ */
+ public NodeRef getNodeRef()
+ {
+ return m_nodeRef;
+ }
+
+ /**
+ * set the node ref
+ *
+ * @param nodeRef NodeRef
+ */
+ public void setNodeRef( NodeRef nodeRef)
+ {
+ m_nodeRef = nodeRef;
+ }
+}
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/LinkNodeFileExtensionPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/LinkNodeFileExtensionPatch.java
new file mode 100644
index 0000000000..914242bfcf
--- /dev/null
+++ b/source/java/org/alfresco/repo/admin/patch/impl/LinkNodeFileExtensionPatch.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.admin.patch.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.Date;
+import java.util.List;
+
+import org.alfresco.i18n.I18NUtil;
+import org.alfresco.model.ContentModel;
+import org.alfresco.repo.admin.patch.AbstractPatch;
+import org.alfresco.repo.domain.hibernate.NodeImpl;
+import org.alfresco.repo.node.db.NodeDaoService;
+import org.alfresco.service.cmr.admin.PatchException;
+import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.springframework.orm.hibernate3.HibernateCallback;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+/**
+ * Checks that all names do not end with ' ' or '.'
+ *
+ * @author David Caruana
+ */
+public class LinkNodeFileExtensionPatch extends AbstractPatch
+{
+ private static final String MSG_SUCCESS = "patch.linkNodeExtension.result";
+ private static final String MSG_REWRITTEN = "patch.linkNodeExtension.rewritten";
+ private static final String ERR_UNABLE_TO_FIX = "patch.linkNodeExtension.err.unable_to_fix";
+
+ private SessionFactory sessionFactory;
+ private NodeDaoService nodeDaoService;
+
+ /**
+ * Default constructor
+ *
+ */
+ public LinkNodeFileExtensionPatch()
+ {
+ }
+
+ /**
+ * Set the session factory
+ *
+ * @param sessionFactory SessionFactory
+ */
+ public void setSessionFactory(SessionFactory sessionFactory)
+ {
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * @param nodeDaoService The service that generates the CRC values
+ */
+ public void setNodeDaoService(NodeDaoService nodeDaoService)
+ {
+ this.nodeDaoService = nodeDaoService;
+ }
+
+ @Override
+ protected void checkProperties()
+ {
+ super.checkProperties();
+ checkPropertyNotNull(sessionFactory, "sessionFactory");
+ checkPropertyNotNull(nodeDaoService, "nodeDaoService");
+ }
+
+ @Override
+ protected String applyInternal() throws Exception
+ {
+ // Initialise the helper
+
+ HibernateHelper helper = new HibernateHelper();
+ helper.setSessionFactory(sessionFactory);
+
+ try
+ {
+ // Fix the link node file names
+
+ return helper.fixNames();
+ }
+ finally
+ {
+ helper.closeWriter();
+ }
+ }
+
+ private class HibernateHelper extends HibernateDaoSupport
+ {
+ private File logFile;
+ private FileChannel channel;
+
+ private HibernateHelper() throws IOException
+ {
+ // Open a log file
+
+ logFile = new File("./LinkNodeExtensionPatch.log");
+ RandomAccessFile outputFile = new RandomAccessFile(logFile, "rw");
+ channel = outputFile.getChannel();
+
+ // Append to the end of the file
+
+ channel.position(channel.size());
+
+ writeLine("").writeLine("");
+ writeLine("LinkNodeExtensionPatch executing on " + new Date());
+ }
+
+ private HibernateHelper write(Object obj) throws IOException
+ {
+ channel.write(ByteBuffer.wrap(obj.toString().getBytes()));
+ return this;
+ }
+ private HibernateHelper writeLine(Object obj) throws IOException
+ {
+ write(obj);
+ write("\n");
+ return this;
+ }
+ private void closeWriter()
+ {
+ try { channel.close(); } catch (Throwable e) {}
+ }
+
+ public String fixNames() throws Exception
+ {
+ // Get the list of nodes to be updated
+
+ @SuppressWarnings("unused")
+ List