Added configuration before file/folder overwrite. Fixed some small mistakes. Fixes...
authorzev <zev@netxms.org>
Thu, 17 Aug 2017 14:23:06 +0000 (17:23 +0300)
committerzev <zev@netxms.org>
Thu, 17 Aug 2017 14:23:06 +0000 (17:23 +0300)
20 files changed:
ChangeLog
include/nms_agent.h
include/nxcldefs.h
src/agent/subagents/filemgr/filemgr.cpp
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/client/netxms-client/src/main/java/org/netxms/client/constants/RCC.java
src/java/client/netxms-client/src/main/java/org/netxms/client/server/AgentFile.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/tools/MessageDialogHelper.java
src/java/netxms-eclipse/FileManager/src/org/netxms/ui/eclipse/filemanager/views/AgentFileManager.java
src/server/core/session.cpp
src/server/libnxsrv/main.cpp
webui/webapp/Core/src/org/netxms/ui/eclipse/tools/MacAddressValidator.java
webui/webapp/Core/src/org/netxms/ui/eclipse/tools/MessageDialogHelper.java
webui/webapp/FileManager/src/org/netxms/ui/eclipse/filemanager/views/AgentFileManager.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/ObjectFigureLargeLabel.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/ObjectTooltip.java
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/CreateInterfaceDialog.java
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/widgets/SensorCommon.java
webui/webapp/Topology/src/org/netxms/ui/eclipse/topology/actions/FindMacAddress.java
webui/webapp/Topology/src/org/netxms/ui/eclipse/topology/dialogs/EnterMacAddressDlg.java

index fd1742b..9e8c396 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,7 +15,7 @@
        - New method "enableRoutingTablePolling" in class "Node"
 - Management console:
        - Improved status map
-- Fixed issues: NX-930, NX-1143, NX-1263, NX-1272, NX-1273, NX-1278, NX-1281, NX-1284, NX-1285, NX-1286
+- Fixed issues: NX-930, NX-1143, NX-1170, NX-1263, NX-1272, NX-1273, NX-1278, NX-1281, NX-1284, NX-1285, NX-1286
 
 
 *
index 022bff4..b6a1687 100644 (file)
 #define ERR_OUT_OF_STATE_REQUEST    ((UINT32)922)
 #define ERR_ENCRYPTION_ERROR        ((UINT32)923)
 #define ERR_MALFORMED_RESPONSE      ((UINT32)924)
+<<<<<<< Updated upstream
 #define ERR_INVALID_OBJECT          ((UINT32)925)
+=======
+#define ERR_FILE_ALREADY_EXISTS     ((UINT32)925)
+#define ERR_FOLDER_ALREADY_EXISTS   ((UINT32)926)
+>>>>>>> Stashed changes
 
 /**
  * Bulk data reconciliation DCI processing status codes
index eb56bd8..ccdd558 100644 (file)
@@ -550,6 +550,8 @@ enum SessionState
 #define RCC_CATEGORY_NAME_EMPTY       ((UINT32)123)
 #define RCC_AGENT_FILE_DOWNLOAD_ERROR ((UINT32)124)
 #define RCC_INVALID_TUNNEL_ID         ((UINT32)125)
+#define RCC_FILE_ALREADY_EXISTS       ((UINT32)126)
+#define RCC_FOLDER_ALREADY_EXISTS     ((UINT32)127)
 
 /**
  * Mask bits for NXCModifyEventTemplate()
index a21d6b7..bfdd974 100644 (file)
@@ -242,6 +242,36 @@ static bool CheckFullPath(TCHAR *folder, bool withHomeDir, bool isModify = false
 #define DIRECTORY       2
 #define SYMLINC         4
 
+/**
+ * Returns if file already exist
+ */
+int CheckFileType(const TCHAR *fileName)
+{
+   NX_STAT_STRUCT st;
+   if (CALL_STAT(fileName, &st) == 0)
+   {
+      if(S_ISDIR(st.st_mode))
+      {
+         return DIRECTORY;
+      }
+      else
+         return REGULAR_FILE;
+   }
+   return -1;
+}
+
+bool CheckAndRequestForOverwritePermissions(const TCHAR *fileName, bool allowOvervirite, NXCPMessage *response)
+{
+   int fileType = CheckFileType(fileName);
+   if(fileType > 0 && !allowOvervirite)
+   {
+      response->setField(VID_RCC, fileType == DIRECTORY ? ERR_FOLDER_ALREADY_EXISTS : ERR_FILE_ALREADY_EXISTS);
+      return false;
+   }
+   else
+      return true;
+}
+
 #ifdef _WIN32
 
 TCHAR *GetFileOwnerWin(const TCHAR *file)
@@ -339,7 +369,7 @@ static bool FillMessageFolderContent(const TCHAR *filePath, const TCHAR *fileNam
  */
 static void GetFolderContent(TCHAR *folder, NXCPMessage *response, bool rootFolder, bool allowMultipart, AbstractCommSession *session)
 {
-   nxlog_debug(5, _T("FILEMGR: GetFolderContent: reading \"%s\" (root=%s, multipart=%s)"), 
+   nxlog_debug(5, _T("FILEMGR: GetFolderContent: reading \"%s\" (root=%s, multipart=%s)"),
       folder, rootFolder ? _T("true") : _T("false"), allowMultipart ? _T("true") : _T("false"));
 
    NXCPMessage *msg;
@@ -378,7 +408,7 @@ static void GetFolderContent(TCHAR *folder, NXCPMessage *response, bool rootFold
          session->sendMessage(msg);
          delete msg;
       }
-      nxlog_debug(5, _T("FILEMGR: GetFolderContent: reading \"%s\" completed"), folder); 
+      nxlog_debug(5, _T("FILEMGR: GetFolderContent: reading \"%s\" completed"), folder);
       return;
    }
 
@@ -431,7 +461,7 @@ static void GetFolderContent(TCHAR *folder, NXCPMessage *response, bool rootFold
    if (allowMultipart)
       delete msg;
 
-   nxlog_debug(5, _T("FILEMGR: GetFolderContent: reading \"%s\" completed"), folder); 
+   nxlog_debug(5, _T("FILEMGR: GetFolderContent: reading \"%s\" completed"), folder);
 }
 
 /**
@@ -542,12 +572,12 @@ static BOOL CopyFile(NX_STAT_STRUCT *st, const TCHAR *oldName, const TCHAR *newN
 /**
  * Move file/folder
  */
-static BOOL MoveFile(TCHAR* oldName, TCHAR* newName)
+static BOOL MoveFile(TCHAR* oldName, TCHAR* newName, overwrite)
 {
 #ifdef _WIN32
    return MoveFileEx(oldName, newName, MOVEFILE_COPY_ALLOWED);
 #else
-   if (Rename(oldName, newName))
+   if (Rename(oldName, newName, true))
    {
       return TRUE;
    }
@@ -759,6 +789,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          request->getFieldAsString(VID_FILE_NAME, oldName, MAX_PATH);
          TCHAR newName[MAX_PATH];
          request->getFieldAsString(VID_NEW_FILE_NAME, newName, MAX_PATH);
+         bool allowOvervirite = request->getFieldAsBoolean(VID_OVERVRITE);
          response->setId(request->getId());
          if (oldName[0] == 0 && newName[0] == 0)
          {
@@ -771,14 +802,15 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
 
          if (CheckFullPath(oldName, false, true) && CheckFullPath(newName, false) && session->isMasterServer())
          {
-            if (Rename(oldName, newName))
-            {
-               response->setField(VID_RCC, ERR_SUCCESS);
-            }
-            else
-            {
-               response->setField(VID_RCC, ERR_IO_FAILURE);
-            }
+            if(CheckAndRequestForOverwritePermissions(newName, allowOvervirite, response))
+               if (Rename(oldName, newName))
+               {
+                  response->setField(VID_RCC, ERR_SUCCESS);
+               }
+               else
+               {
+                  response->setField(VID_RCC, ERR_IO_FAILURE);
+               }
          }
          else
          {
@@ -793,6 +825,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          request->getFieldAsString(VID_FILE_NAME, oldName, MAX_PATH);
          TCHAR newName[MAX_PATH];
          request->getFieldAsString(VID_NEW_FILE_NAME, newName, MAX_PATH);
+         bool allowOvervirite = request->getFieldAsBoolean(VID_OVERVRITE);
          response->setId(request->getId());
          if ((oldName[0] == 0) && (newName[0] == 0))
          {
@@ -805,13 +838,16 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
 
          if (CheckFullPath(oldName, false, true) && CheckFullPath(newName, false) && session->isMasterServer())
          {
-            if(MoveFile(oldName, newName))
+            if(CheckAndRequestForOverwritePermissions(newName, allowOvervirite, response))
             {
-               response->setField(VID_RCC, ERR_SUCCESS);
-            }
-            else
-            {
-               response->setField(VID_RCC, ERR_IO_FAILURE);
+               if(MoveFile(oldName, newName))
+               {
+                  response->setField(VID_RCC, ERR_SUCCESS);
+               }
+               else
+               {
+                  response->setField(VID_RCC, ERR_IO_FAILURE);
+               }
             }
          }
          else
@@ -825,6 +861,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
       {
          TCHAR name[MAX_PATH];
          request->getFieldAsString(VID_FILE_NAME, name, MAX_PATH);
+         bool allowOvervirite = request->getFieldAsBoolean(VID_OVERVRITE);
          response->setId(request->getId());
          if (name[0] == 0)
          {
@@ -836,7 +873,8 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
 
          if (CheckFullPath(name, false, true) && session->isMasterServer())
          {
-            response->setField(VID_RCC, session->openFile(name, request->getId(), request->getFieldAsTime(VID_MODIFICATION_TIME)));
+            if(CheckAndRequestForOverwritePermissions(name, allowOvervirite, response))
+               response->setField(VID_RCC, session->openFile(name, request->getId(), request->getFieldAsTime(VID_MODIFICATION_TIME)));
          }
          else
          {
@@ -925,6 +963,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
       {
          TCHAR directory[MAX_PATH];
          request->getFieldAsString(VID_FILE_NAME, directory, MAX_PATH);
+         bool allowOvervirite = request->getFieldAsBoolean(VID_OVERVRITE);
          response->setId(request->getId());
          if (directory[0] == 0)
          {
@@ -936,14 +975,17 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
 
          if (CheckFullPath(directory, false, true) && session->isMasterServer())
          {
-            if (CreateFolder(directory))
-            {
-               response->setField(VID_RCC, ERR_SUCCESS);
-            }
-            else
+            if(CheckAndRequestForOverwritePermissions(directory, allowOvervirite, response))
             {
-               AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(CMD_FILEMGR_CREATE_FOLDER): Could not create directory"));
-               response->setField(VID_RCC, ERR_IO_FAILURE);
+               if (CreateFolder(directory))
+               {
+                  response->setField(VID_RCC, ERR_SUCCESS);
+               }
+               else
+               {
+                  AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(CMD_FILEMGR_CREATE_FOLDER): Could not create directory"));
+                  response->setField(VID_RCC, ERR_IO_FAILURE);
+               }
             }
          }
          else
index fa9ca9f..6b28d12 100644 (file)
@@ -8009,7 +8009,7 @@ public class NXCSession
     * @throws IOException  if socket or file I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void uploadLocalFileToAgent(long nodeId, File localFile, String remoteFileName, ProgressListener listener)
+   public void uploadLocalFileToAgent(long nodeId, File localFile, String remoteFileName, boolean overvrite, ProgressListener listener)
       throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_FILEMGR_UPLOAD);
@@ -8020,6 +8020,7 @@ public class NXCSession
       msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
       msg.setField(NXCPCodes.VID_FILE_NAME, remoteFileName);
       msg.setField(NXCPCodes.VID_MODIFICATION_TIME, new Date(localFile.lastModified()));
+      msg.setField(NXCPCodes.VID_OVERVRITE, overvrite);
       sendMessage(msg);
       NXCPMessage response = waitForRCC(msg.getMessageId());
       sendFile(msg.getMessageId(), localFile, listener, response.getFieldAsBoolean(NXCPCodes.VID_ENABLE_COMPRESSION));
@@ -8033,11 +8034,12 @@ public class NXCSession
     * @throws IOException  if socket or file I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void createFolderOnAgent(long nodeId, String folder) throws IOException, NXCException
+   public void createFolderOnAgent(long nodeId, String folder, boolean overvrite) throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_FILEMGR_CREATE_FOLDER);
       msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
       msg.setField(NXCPCodes.VID_FILE_NAME, folder);
+      msg.setField(NXCPCodes.VID_OVERVRITE, overvrite);
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
    }
@@ -8193,12 +8195,13 @@ public class NXCSession
     * @throws IOException  if socket or file I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void renameAgentFile(long nodeId, String oldName, String newFileName) throws IOException, NXCException
+   public void renameAgentFile(long nodeId, String oldName, String newFileName, boolean overvrite) throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_FILEMGR_RENAME_FILE);
       msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
       msg.setField(NXCPCodes.VID_FILE_NAME, oldName);
       msg.setField(NXCPCodes.VID_NEW_FILE_NAME, newFileName);
+      msg.setField(NXCPCodes.VID_OVERVRITE, overvrite);
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
    }
@@ -8212,12 +8215,13 @@ public class NXCSession
     * @throws IOException  if socket or file I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void moveAgentFile(long nodeId, String oldName, String newFileName) throws IOException, NXCException
+   public void moveAgentFile(long nodeId, String oldName, String newFileName, boolean overvrite) throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_FILEMGR_MOVE_FILE);
       msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
       msg.setField(NXCPCodes.VID_FILE_NAME, oldName);
       msg.setField(NXCPCodes.VID_NEW_FILE_NAME, newFileName);
+      msg.setField(NXCPCodes.VID_OVERVRITE, overvrite);
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
    }
index 30c1a31..58f94ca 100644 (file)
@@ -119,6 +119,8 @@ public final class RCC extends CommonRCC
    public static final int CATEGORY_NAME_EMPTY = 123;
    public static final int AGENT_FILE_DOWNLOAD_ERROR = 124;
    public static final int INVALID_TUNNEL_ID = 125;
+   public static final int FILE_ALREADY_EXISTS = 126;
+   public static final int FOLDER_ALREADY_EXIST = 127;
        
        // SNMP-specific, has no corresponding RCC_xxx constants in C library
        public static final int BAD_MIB_FILE_HEADER = 1001;
index f3cf668..c798446 100644 (file)
@@ -181,13 +181,17 @@ public class AgentFile
     */
    public void addChield(AgentFile chield)
    {
+      if(children == null)
+         return;
       boolean childReplaced = false;
       for(int i=0; i<children.size(); i++)
       {
          if(children.get(i).getName().equalsIgnoreCase(chield.getName()))
          {
-            children.add(i, chield);
+            if(chield.getType() != DIRECTORY)
+               children.set(i, chield);
             childReplaced = true;
+            break;
          }
       }
       if(!childReplaced)
@@ -202,8 +206,10 @@ public class AgentFile
    public String getFullName()
    {
       if (parent == null)
+      {
          return name;
-      return parent.getFullName() + "/" + name;
+      }
+      return parent.getFullName() + ((parent.getFullName().contains("\\") || parent.getFullName().contains(":")) ? "\\" : "/") + name;
    }
 
    /**
index 5331547..984b107 100644 (file)
@@ -154,6 +154,24 @@ public class MessageDialogHelper
                                                 IDialogConstants.CANCEL_LABEL }, parent, title, label, message);
       return msg.openMsg();
    }
+   
+   /**
+    * Convenience method to open a standard one button (OK) warning dialog with a check box
+    * to remember selection. 
+    * 
+    * @param parent the parent shell of the dialog, or <code>null</code> if none
+    * @param title the dialog's title, or <code>null</code> if none
+    * @param label the label for the check box
+    * @param message the message
+    * @return 
+    */
+   public static DialogData openOneButtonWarningWithCheckbox(Shell parent, String title, String label, String message)
+   {
+      MessageDialogWithCheckbox msg = new MessageDialogWithCheckbox(
+                                                MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL}, 
+                                                parent, title, label, message);
+      return msg.openMsg();
+   }
 
        /**
         * Helper class to show message dialog with check box (for example to add "do not show again" option)
index 14ac70f..8ec29aa 100644 (file)
@@ -65,12 +65,14 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Item;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
@@ -81,6 +83,7 @@ import org.netxms.client.AgentFileData;
 import org.netxms.client.NXCException;
 import org.netxms.client.NXCSession;
 import org.netxms.client.ProgressListener;
+import org.netxms.client.constants.RCC;
 import org.netxms.client.objects.Node;
 import org.netxms.client.server.AgentFile;
 import org.netxms.ui.eclipse.actions.RefreshAction;
@@ -96,6 +99,7 @@ import org.netxms.ui.eclipse.filemanager.views.helpers.AgentFileLabelProvider;
 import org.netxms.ui.eclipse.filemanager.views.helpers.ViewAgentFilesProvider;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.DialogData;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 import org.netxms.ui.eclipse.widgets.FilterText;
@@ -422,7 +426,7 @@ public class AgentFileManager extends ViewPart
     */
    private void doRename(final AgentFile agentFile, final String newName)
    {
-      new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
+      new ConsoleJob("Rename file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
          @Override
          protected String getErrorMessage()
          {
@@ -432,16 +436,35 @@ public class AgentFileManager extends ViewPart
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
          {
-            session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName); //$NON-NLS-1$
-
-            runInUIThread(new Runnable() {
+            final NestedVerifyOverwrite verify =  new NestedVerifyOverwrite(agentFile.getType(), newName, true, true, false) {
+               
                @Override
-               public void run()
+               public void executeAction() throws NXCException, IOException
                {
-                  agentFile.setName(newName);
-                  viewer.refresh(agentFile, true);
+                  session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName, false); //$NON-NLS-1$
                }
-            });
+               
+               @Override
+               public void executeSameFunctionWithOverwrite() throws IOException, NXCException
+               {
+                  session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName, true); //$NON-NLS-1$
+               }
+            };
+            verify.run(viewer.getControl().getDisplay());
+    
+            if(verify.isOkPressed())
+            {
+               runInUIThread(new Runnable() {
+                  @Override
+                  public void run()
+                  {
+                     if(verify.isOkPressed())
+                        refreshFileOrDirectory();
+                     agentFile.setName(newName);
+                     viewer.refresh(agentFile, true);
+                  }
+               });
+            }
          }
       }.start();
    }
@@ -475,7 +498,7 @@ public class AgentFileManager extends ViewPart
          @Override
          public void run()
          {
-            uploadFile();
+            uploadFile(false);
          }
       };
       actionUploadFile.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.uploadFile"); //$NON-NLS-1$
@@ -783,7 +806,7 @@ public class AgentFileManager extends ViewPart
    /**
     * Upload local file to agent
     */
-   private void uploadFile()
+   private void uploadFile(final boolean overvrite)
    {
       IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
       if (selection.isEmpty())
@@ -808,25 +831,56 @@ public class AgentFileManager extends ViewPart
                   String remoteFile = fileList.get(i).getName();
                   if(fileList.size() == 1)
                      remoteFile = dlg.getRemoteFileName();
+                  final String rFileName = remoteFile;
                   
-                  session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+remoteFile, new ProgressListener() { //$NON-NLS-1$
-                     private long prevWorkDone = 0;
-   
+                  new NestedVerifyOverwrite(localFile.isDirectory() ? AgentFile.DIRECTORY : AgentFile.FILE, localFile.getName(), true, true, false) {
+                     
                      @Override
-                     public void setTotalWorkAmount(long workTotal)
-                     {
-                        monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
-                              (int)workTotal);
+                     public void executeAction() throws NXCException, IOException
+                     {                        
+                        session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+rFileName, overvrite, new ProgressListener() { //$NON-NLS-1$
+                           private long prevWorkDone = 0;
+         
+                           @Override
+                           public void setTotalWorkAmount(long workTotal)
+                           {
+                              monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
+                                    (int)workTotal);
+                           }
+         
+                           @Override
+                           public void markProgress(long workDone)
+                           {
+                              monitor.worked((int)(workDone - prevWorkDone));
+                              prevWorkDone = workDone;
+                           }
+                        });
+                        monitor.done(); 
                      }
-   
+
                      @Override
-                     public void markProgress(long workDone)
+                     public void executeSameFunctionWithOverwrite() throws IOException, NXCException
                      {
-                        monitor.worked((int)(workDone - prevWorkDone));
-                        prevWorkDone = workDone;
+                        session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+rFileName, true, new ProgressListener() { //$NON-NLS-1$
+                           private long prevWorkDone = 0;
+         
+                           @Override
+                           public void setTotalWorkAmount(long workTotal)
+                           {
+                              monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
+                                    (int)workTotal);
+                           }
+         
+                           @Override
+                           public void markProgress(long workDone)
+                           {
+                              monitor.worked((int)(workDone - prevWorkDone));
+                              prevWorkDone = workDone;
+                           }
+                        });
+                        monitor.done(); 
                      }
-                  });
-                  monitor.done(); 
+                  }.run(viewer.getControl().getDisplay());
                }
                
                upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
@@ -849,91 +903,177 @@ public class AgentFileManager extends ViewPart
       }
    }
    
-   /**
-    * Upload local folder to agent
-    */
-   private void uploadFolder()
+   class UploadConsoleJob extends ConsoleJob
    {
-      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
-      if (selection.isEmpty())
-         return;
-
-      final Object[] objects = selection.toArray();
-      final AgentFile upladFolder = ((AgentFile)objects[0]).isDirectory() ? ((AgentFile)objects[0]) : ((AgentFile)objects[0])
-            .getParent();
+      private boolean askFolderOverwrite;
+      private boolean askFileOverwrite;
+      private boolean overwrite;
+      private File folder;
+      private AgentFile uploadFolder;
+      private String remoteFileName;
+
+      public UploadConsoleJob(String name, IWorkbenchPart wbPart, String pluginId, Object jobFamily, File folder, final AgentFile uploadFolder, final String remoteFileName)
+      {
+         super(name, wbPart, pluginId, jobFamily);
+         askFolderOverwrite = true;
+         askFileOverwrite = true;
+         overwrite = false;
+         this.folder = folder;
+         this.uploadFolder = uploadFolder;
+         this.remoteFileName = remoteFileName;
+      }
 
-      final StartClientToAgentFolderUploadDialog dlg = new StartClientToAgentFolderUploadDialog(getSite().getShell());
-      if (dlg.open() == Window.OK)
+      @Override
+      protected void runInternal(IProgressMonitor monitor) throws Exception
       {
-         final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-         new ConsoleJob(Messages.get().AgentFileManager_UploadFolderJobTitle, null, Activator.PLUGIN_ID, null) {
+         NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, folder.getName(), askFolderOverwrite, askFileOverwrite, overwrite) {
+            
             @Override
-            protected void runInternal(final IProgressMonitor monitor) throws Exception
-            {
-               File folder = dlg.getLocalFile();
-               session.createFolderOnAgent(objectId, upladFolder.getFullName()+"/"+dlg.getRemoteFileName()); //$NON-NLS-1$
-               uploadFilesInFolder(folder, upladFolder.getFullName()+"/"+dlg.getRemoteFileName(), monitor); //$NON-NLS-1$
-               
-               upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
-               runInUIThread(new Runnable() {
-                  @Override
-                  public void run()
-                  {
-                     viewer.refresh(upladFolder, true);
-                  }
-               });
+            public void executeAction() throws NXCException, IOException
+            {                        
+               session.createFolderOnAgent(objectId, uploadFolder.getFullName()+"/"+remoteFileName, false); //$NON-NLS-1$
             }
 
             @Override
-            protected String getErrorMessage()
+            public void executeSameFunctionWithOverwrite() throws NXCException, IOException
             {
-               return Messages.get().UploadFileToServer_JobError;
+               session.createFolderOnAgent(objectId, uploadFolder.getFullName()+"/"+remoteFileName, true); //$NON-NLS-1$
             }
-         }.start();
+         };
+         verify.run(viewer.getControl().getDisplay());
+         askFolderOverwrite = verify.askFolderOverwrite();
+         
+         uploadFilesInFolder(folder, uploadFolder.getFullName()+"/"+remoteFileName, monitor); //$NON-NLS-1$
+         
+         uploadFolder.setChildren(session.listAgentFiles(uploadFolder, uploadFolder.getFullName(), objectId));
+         runInUIThread(new Runnable() {
+            @Override
+            public void run()
+            {
+               viewer.refresh(uploadFolder, true);
+            }
+         });
       }
+
+      @Override
+      protected String getErrorMessage()
+      {
+         return Messages.get().UploadFileToServer_JobError;
+      }
+      
+      /**
+       * Recursively uploads files to agent and creates correct folders
+       * 
+       * @param folder
+       * @param upladFolder
+       * @param monitor
+       * @throws NXCException
+       * @throws IOException
+       */
+      public void uploadFilesInFolder(final File folder, final String uploadFolder, final IProgressMonitor monitor) throws NXCException, IOException 
+      {
+         for(final File fileEntry : folder.listFiles())
+         {
+             if (fileEntry.isDirectory()) 
+             {
+                NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, fileEntry.getName(), askFolderOverwrite, askFileOverwrite, overwrite) {
+                   
+                   @Override
+                   public void executeAction() throws NXCException, IOException
+                   {                        
+                      session.createFolderOnAgent(objectId, uploadFolder + "/" + fileEntry.getName(), false); //$NON-NLS-1$
+                   }
+
+                   @Override
+                   public void executeSameFunctionWithOverwrite() throws NXCException, IOException
+                   {
+                      session.createFolderOnAgent(objectId, uploadFolder + "/" + fileEntry.getName(), true); //$NON-NLS-1$
+                   }
+                };
+                verify.run(viewer.getControl().getDisplay());
+                askFolderOverwrite = verify.askFolderOverwrite();
+                
+                uploadFilesInFolder(fileEntry, uploadFolder + "/" + fileEntry.getName(), monitor); //$NON-NLS-1$
+             } 
+             else 
+             {      
+                NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.FILE, fileEntry.getName(), askFolderOverwrite, askFileOverwrite, overwrite) {
+                   
+                   @Override
+                   public void executeAction() throws NXCException, IOException
+                   {                        
+                      session.uploadLocalFileToAgent(objectId, fileEntry, uploadFolder + "/" + fileEntry.getName(), overwrite, new ProgressListener() { //$NON-NLS-1$
+                         private long prevWorkDone = 0;
+
+                         @Override
+                         public void setTotalWorkAmount(long workTotal)
+                         {
+                            monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + fileEntry.getAbsolutePath(),
+                                  (int)workTotal);
+                         }
+
+                         @Override
+                         public void markProgress(long workDone)
+                         {
+                            monitor.worked((int)(workDone - prevWorkDone));
+                            prevWorkDone = workDone;
+                         }
+                      });
+                      monitor.done();
+                   }
+
+                   @Override
+                   public void executeSameFunctionWithOverwrite() throws NXCException, IOException
+                   {
+                      session.uploadLocalFileToAgent(objectId, fileEntry, uploadFolder + "/" + fileEntry.getName(), true, new ProgressListener() { //$NON-NLS-1$
+                      private long prevWorkDone = 0;
+
+                      @Override
+                      public void setTotalWorkAmount(long workTotal)
+                      {
+                         monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + fileEntry.getAbsolutePath(),
+                               (int)workTotal);
+                      }
+
+                      @Override
+                      public void markProgress(long workDone)
+                      {
+                         monitor.worked((int)(workDone - prevWorkDone));
+                         prevWorkDone = workDone;
+                      }
+                   });
+                   monitor.done(); 
+                   }
+                };
+                verify.run(viewer.getControl().getDisplay());
+                askFileOverwrite = verify.askFileOverwrite();
+                if(!askFileOverwrite)
+                   overwrite = verify.isOkPressed();
+             }
+         }
+     }
    }
    
    /**
-    * Recursively uploads files to agent and creates correct folders
-    * 
-    * @param folder
-    * @param upladFolder
-    * @param monitor
-    * @throws NXCException
-    * @throws IOException
+    * Upload local folder to agent
     */
-   public void uploadFilesInFolder(final File folder, final String uploadFolder, final IProgressMonitor monitor) throws NXCException, IOException 
+   private void uploadFolder()
    {
-      for(final File fileEntry : folder.listFiles())
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if (selection.isEmpty())
+         return;
+
+      final Object[] objects = selection.toArray();
+      final AgentFile upladFolder = ((AgentFile)objects[0]).isDirectory() ? ((AgentFile)objects[0]) : ((AgentFile)objects[0])
+            .getParent();
+
+      final StartClientToAgentFolderUploadDialog dlg = new StartClientToAgentFolderUploadDialog(getSite().getShell());
+      if (dlg.open() == Window.OK)
       {
-          if (fileEntry.isDirectory()) 
-          {
-             session.createFolderOnAgent(objectId, uploadFolder + "/" + fileEntry.getName()); //$NON-NLS-1$
-             uploadFilesInFolder(fileEntry, uploadFolder + "/" + fileEntry.getName(), monitor); //$NON-NLS-1$
-          } 
-          else 
-          {
-             session.uploadLocalFileToAgent(objectId, fileEntry, uploadFolder + "/" + fileEntry.getName(), new ProgressListener() { //$NON-NLS-1$
-                private long prevWorkDone = 0;
-
-                @Override
-                public void setTotalWorkAmount(long workTotal)
-                {
-                   monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + fileEntry.getAbsolutePath(),
-                         (int)workTotal);
-                }
-
-                @Override
-                public void markProgress(long workDone)
-                {
-                   monitor.worked((int)(workDone - prevWorkDone));
-                   prevWorkDone = workDone;
-                }
-             });
-             monitor.done(); 
-          }
+         ConsoleJob job = new UploadConsoleJob(Messages.get().AgentFileManager_UploadFolderJobTitle, null, Activator.PLUGIN_ID, null, dlg.getLocalFile(), upladFolder, dlg.getRemoteFileName());
+         job.start();
       }
-  }
+   }   
 
    /**
     * Delete selected file
@@ -1048,6 +1188,7 @@ public class AgentFileManager extends ViewPart
          String[] filterNames = { Messages.get().AgentFileManager_AllFiles };
          dlg.setFilterNames(filterNames);
          dlg.setFileName(sf.getName());
+         dlg.setOverwrite(true);
          target = dlg.open();
       }
       else
@@ -1232,19 +1373,36 @@ public class AgentFileManager extends ViewPart
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
          {
-            session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName()); //$NON-NLS-1$
+            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(object.getType(), object.getName(), true, true, false) {
+               
+               @Override
+               public void executeAction() throws NXCException, IOException
+               {
+                  session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false); //$NON-NLS-1$
+               }
 
-            runInUIThread(new Runnable() {
                @Override
-               public void run()
+               public void executeSameFunctionWithOverwrite() throws IOException, NXCException
                {
-                  object.getParent().removeChield(object);
-                  viewer.refresh(object.getParent(), true);
-                  object.setParent(target);
-                  target.addChield(object);
-                  viewer.refresh(object.getParent(), true);
+                  session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), true); //$NON-NLS-1$                  
                }
-            });
+            };
+            verify.run(viewer.getControl().getDisplay());
+            
+            if(verify.isOkPressed())
+            {
+               runInUIThread(new Runnable() {
+                  @Override
+                  public void run()
+                  {
+                     object.getParent().removeChield(object);
+                     viewer.refresh(object.getParent(), true);
+                     object.setParent(target);
+                     target.addChield(object);
+                     viewer.refresh(object.getParent(), true);
+                  }
+               });
+            }
          }
       }.start();
    }
@@ -1277,8 +1435,22 @@ public class AgentFileManager extends ViewPart
 
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
-         {
-            session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder); //$NON-NLS-1$
+         { 
+            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, newFolder, true, true, false) {
+               
+               @Override
+               public void executeAction() throws NXCException, IOException
+               {
+                  session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder, false); //$NON-NLS-1$
+               }
+   
+               @Override
+               public void executeSameFunctionWithOverwrite() throws IOException, NXCException
+               {
+                  session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder, true); //$NON-NLS-1$             
+               }
+            };
+            verify.run(viewer.getControl().getDisplay());
             parentFolder.setChildren(session.listAgentFiles(parentFolder, parentFolder.getFullName(), objectId));
 
             runInUIThread(new Runnable() {
@@ -1352,7 +1524,9 @@ public class AgentFileManager extends ViewPart
          return;
 
       String filePath = ((AgentFile)selection.getFirstElement()).getFullName();
-      WidgetHelper.copyToClipboard(filePath.substring(1, filePath.length())); // Substring is made to remove first "/"
+      filePath = filePath.replace("\\\\", "\\");
+      filePath = filePath.replace("//", "/");      
+      WidgetHelper.copyToClipboard(filePath);
    }
 
    /*
@@ -1398,4 +1572,102 @@ public class AgentFileManager extends ViewPart
       filter.setFilterString(text);
       viewer.refresh(false);
    }
+   
+   /**
+    * Nested class that check if file already exist and it should be overwritten
+    *
+    */
+   abstract class NestedVerifyOverwrite
+   {
+      private boolean okPresseed;
+      private int type;
+      private String name;
+      private boolean askFolderOverwrite;
+      private boolean askFileOverwrite;
+      private boolean overwrite;
+      
+      public NestedVerifyOverwrite(int fileType, String fileName, boolean askFolderOverwrite, boolean askFileOverwrite, boolean overwrite)
+      {
+         type = fileType;
+         name = fileName;
+         this.askFolderOverwrite = askFolderOverwrite;
+         this.askFileOverwrite = askFileOverwrite;
+         this.overwrite = overwrite;
+         okPresseed = true;
+      }
+      
+      public boolean askFolderOverwrite()
+      {
+         return askFolderOverwrite;
+      }
+      
+      public boolean askFileOverwrite()
+      {
+         return askFileOverwrite;
+      }
+      
+      public void run(Display disp) throws IOException, NXCException
+      {         
+         try
+         {
+            executeAction();
+         }
+         catch(final NXCException e)
+         {
+            if(e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST || type == AgentFile.DIRECTORY)
+            {
+               if(askFolderOverwrite)
+               {
+                  disp.syncExec(new Runnable() {
+                     @Override
+                     public void run()
+                     {
+                        DialogData data = MessageDialogHelper.openOneButtonWarningWithCheckbox(getSite().getShell(), 
+                              String.format("%s already exist", e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File"), 
+                              "Do not show again for this upload", String.format("%s %s already exist",e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File", name));
+                        askFolderOverwrite = !data.getSaveSelection();
+                        okPresseed = false;
+                     }
+                  });
+               }
+            }   
+            else if(e.getErrorCode() == RCC.FILE_ALREADY_EXISTS ||  e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST)
+            {
+               if(askFileOverwrite)
+               {
+                  disp.syncExec(new Runnable() {
+                     @Override
+                     public void run()
+                     {
+   
+                        DialogData data = MessageDialogHelper.openWarningWithCheckbox(getSite().getShell(), 
+                              String.format("%s overwrite confirmation", type == AgentFile.DIRECTORY ? "Folder" : "File"), 
+                              "Save chose for current upload files",
+                              String.format("%s with %s name already exists. Are you sure you want to overwrite it?", e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File", name));
+                        askFileOverwrite = !data.getSaveSelection();
+                        okPresseed = data.isOkPressed();                           
+                     }
+                  });
+                  if(okPresseed)                     
+                     executeSameFunctionWithOverwrite();
+               }
+               else
+               {
+                  if(overwrite)
+                  {
+                     executeSameFunctionWithOverwrite();
+                  }
+               }
+            }
+            else
+               throw e;
+         }
+      }
+      public boolean isOkPressed()
+      {
+         return okPresseed;
+      }
+      public abstract void executeAction() throws NXCException, IOException;
+      public abstract void executeSameFunctionWithOverwrite() throws NXCException, IOException;
+   }
 }
index 77b44a9..f28c2ff 100644 (file)
@@ -13323,7 +13323,7 @@ void ClientSession::uploadUserFileToAgent(NXCPMessage *request)
                   }
                   else
                   {
-                     msg.setField(VID_RCC, rcc);
+                     msg.setField(VID_RCC, AgentErrorToRCC(rcc));
                      debugPrintf(6, _T("ClientSession::getAgentFolderContent: Error on agent: %d"), rcc);
                   }
                }
index 68d7edf..9822475 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 ** NetXMS - Network Management System
 ** Server Library
 ** Copyright (C) 2003-2016 Victor Kirhenshtein
@@ -114,6 +114,10 @@ UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err)
          return RCC_ENCRYPTION_ERROR;
       case ERR_OUT_OF_STATE_REQUEST:
          return RCC_OUT_OF_STATE_REQUEST;
+      case ERR_FILE_ALREADY_EXISTS:
+         return RCC_FILE_ALREADY_EXISTS;
+      case ERR_FOLDER_ALREADY_EXISTS:
+         return RCC_FOLDER_ALREADY_EXISTS;
    }
    return RCC_AGENT_ERROR;
 }
index 41143e6..56bf15a 100644 (file)
@@ -18,8 +18,8 @@
  */
 package org.netxms.ui.eclipse.tools;
 
-import org.netxms.client.MacAddress;
-import org.netxms.client.MacAddressFormatException;
+import org.netxms.base.MacAddress;
+import org.netxms.base.MacAddressFormatException;
 import org.netxms.ui.eclipse.console.Messages;
 
 /**
index f2c583e..b8cd0d9 100644 (file)
@@ -155,6 +155,24 @@ public class MessageDialogHelper
                                                       JFaceResources.getString(IDialogLabelKeys.CANCEL_LABEL_KEY) }, parent, title, label, message);
       return msg.openMsg();
    }
+   
+   /**
+    * Convenience method to open a standard one button (OK) warning dialog with a check box
+    * to remember selection. 
+    * 
+    * @param parent the parent shell of the dialog, or <code>null</code> if none
+    * @param title the dialog's title, or <code>null</code> if none
+    * @param label the label for the check box
+    * @param message the message
+    * @return 
+    */
+   public static DialogData openOneButtonWarningWithCheckbox(Shell parent, String title, String label, String message)
+   {
+      MessageDialogWithCheckbox msg = new MessageDialogWithCheckbox(
+                                                MessageDialog.WARNING, new String[] { JFaceResources.getString(IDialogLabelKeys.OK_LABEL_KEY)}, 
+                                                parent, title, label, message);
+      return msg.openMsg();
+   }
 
        /**
         * Helper class to show message dialog with check box (for example to add "do not show again" option)
index 91aff0a..78c21e0 100644 (file)
@@ -66,6 +66,7 @@ import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Item;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.IActionBars;
@@ -81,6 +82,7 @@ import org.netxms.client.AgentFileData;
 import org.netxms.client.NXCException;
 import org.netxms.client.NXCSession;
 import org.netxms.client.ProgressListener;
+import org.netxms.client.constants.RCC;
 import org.netxms.client.objects.Node;
 import org.netxms.client.server.AgentFile;
 import org.netxms.ui.eclipse.actions.RefreshAction;
@@ -96,6 +98,7 @@ import org.netxms.ui.eclipse.filemanager.views.helpers.AgentFileLabelProvider;
 import org.netxms.ui.eclipse.filemanager.views.helpers.ViewAgentFilesProvider;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.DialogData;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 import org.netxms.ui.eclipse.widgets.FilterText;
@@ -421,7 +424,7 @@ public class AgentFileManager extends ViewPart
     */
    private void doRename(final AgentFile agentFile, final String newName)
    {
-      new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
+      new ConsoleJob("Rename file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
          @Override
          protected String getErrorMessage()
          {
@@ -431,16 +434,35 @@ public class AgentFileManager extends ViewPart
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
          {
-            session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName); //$NON-NLS-1$
-
-            runInUIThread(new Runnable() {
+            final NestedVerifyOverwrite verify =  new NestedVerifyOverwrite(agentFile.getType(), newName, true, true, false) {
+               
                @Override
-               public void run()
+               public void executeAction() throws NXCException, IOException
                {
-                  agentFile.setName(newName);
-                  viewer.refresh(agentFile, true);
+                  session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName, false); //$NON-NLS-1$
                }
-            });
+               
+               @Override
+               public void executeSameFunctionWithOverwrite() throws IOException, NXCException
+               {
+                  session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName, true); //$NON-NLS-1$
+               }
+            };
+            verify.run(viewer.getControl().getDisplay());
+    
+            if(verify.isOkPressed())
+            {
+               runInUIThread(new Runnable() {
+                  @Override
+                  public void run()
+                  {
+                     if(verify.isOkPressed())
+                        refreshFileOrDirectory();
+                     agentFile.setName(newName);
+                     viewer.refresh(agentFile, true);
+                  }
+               });
+            }
          }
       }.start();
    }
@@ -474,12 +496,12 @@ public class AgentFileManager extends ViewPart
          @Override
          public void run()
          {
-            uploadFile();
+            uploadFile(false);
          }
       };
       actionUploadFile.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.uploadFile"); //$NON-NLS-1$
       handlerService.activateHandler(actionUploadFile.getActionDefinitionId(), new ActionHandler(actionUploadFile));
-      
+
       actionDelete = new Action(Messages.get().AgentFileManager_Delete, SharedIcons.DELETE_OBJECT) {
          @Override
          public void run()
@@ -773,7 +795,7 @@ public class AgentFileManager extends ViewPart
    /**
     * Upload local file to agent
     */
-   private void uploadFile()
+   private void uploadFile(final boolean overvrite)
    {
       IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
       if (selection.isEmpty())
@@ -798,26 +820,56 @@ public class AgentFileManager extends ViewPart
                   String remoteFile = fileList.get(i).getName();
                   if(fileList.size() == 1)
                      remoteFile = dlg.getRemoteFileName();
+                  final String rFileName = remoteFile;
                   
-                          session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+remoteFile, new ProgressListener() { //$NON-NLS-1$
-                             private long prevWorkDone = 0;
-
-                             @Override
-                             public void setTotalWorkAmount(long workTotal)
-                             {
-                                      monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix
-                                            + localFile.getAbsolutePath(),
-                                      (int)workTotal);
-                             }
-
-                             @Override
-                             public void markProgress(long workDone)
-                             {
-                                monitor.worked((int)(workDone - prevWorkDone));
-                                prevWorkDone = workDone;
-                             }
-                          });
-                          monitor.done(); 
+                  new NestedVerifyOverwrite(localFile.isDirectory() ? AgentFile.DIRECTORY : AgentFile.FILE, localFile.getName(), true, true, false) {
+                     
+                     @Override
+                     public void executeAction() throws NXCException, IOException
+                     {                        
+                        session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+rFileName, overvrite, new ProgressListener() { //$NON-NLS-1$
+                           private long prevWorkDone = 0;
+         
+                           @Override
+                           public void setTotalWorkAmount(long workTotal)
+                           {
+                              monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
+                                    (int)workTotal);
+                           }
+         
+                           @Override
+                           public void markProgress(long workDone)
+                           {
+                              monitor.worked((int)(workDone - prevWorkDone));
+                              prevWorkDone = workDone;
+                           }
+                        });
+                        monitor.done(); 
+                     }
+
+                     @Override
+                     public void executeSameFunctionWithOverwrite() throws IOException, NXCException
+                     {
+                        session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+rFileName, true, new ProgressListener() { //$NON-NLS-1$
+                           private long prevWorkDone = 0;
+         
+                           @Override
+                           public void setTotalWorkAmount(long workTotal)
+                           {
+                              monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
+                                    (int)workTotal);
+                           }
+         
+                           @Override
+                           public void markProgress(long workDone)
+                           {
+                              monitor.worked((int)(workDone - prevWorkDone));
+                              prevWorkDone = workDone;
+                           }
+                        });
+                        monitor.done(); 
+                     }
+                  }.run(viewer.getControl().getDisplay());
                }
                
                upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
@@ -839,94 +891,6 @@ public class AgentFileManager extends ViewPart
          }.start();
       }
    }
-   
-   /**
-    * Upload local folder to agent
-    */
-   /*
-   private void uploadFolder()
-   {
-      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
-      if (selection.isEmpty())
-         return;
-
-      final Object[] objects = selection.toArray();
-      final AgentFile upladFolder = ((AgentFile)objects[0]).isDirectory() ? ((AgentFile)objects[0]) : ((AgentFile)objects[0])
-            .getParent();
-
-      final StartClientToAgentFolderUploadDialog dlg = new StartClientToAgentFolderUploadDialog(getSite().getShell());
-      if (dlg.open() == Window.OK)
-      {
-         final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-         new ConsoleJob(Messages.get().AgentFileManager_UploadFolderJobTitle, null, Activator.PLUGIN_ID, null) {
-            @Override
-            protected void runInternal(final IProgressMonitor monitor) throws Exception
-            {
-               File folder = dlg.getLocalFile();
-               session.createFolderOnAgent(objectId, upladFolder.getFullName()+"/"+dlg.getRemoteFileName()); //$NON-NLS-1$
-               uploadFilesInFolder(folder, upladFolder.getFullName()+"/"+dlg.getRemoteFileName(), monitor); //$NON-NLS-1$
-               
-               upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
-               runInUIThread(new Runnable() {
-                  @Override
-                  public void run()
-                  {
-                     viewer.refresh(upladFolder, true);
-                  }
-               });
-            }
-
-            @Override
-            protected String getErrorMessage()
-            {
-               return Messages.get().UploadFileToServer_JobError;
-            }
-         }.start();
-      }
-   }   
-    */
-   
-   /**
-    * Recursively uploads files to agent and creates correct folders
-    * 
-    * @param folder
-    * @param upladFolder
-    * @param monitor
-    * @throws NXCException
-    * @throws IOException
-    */
-   public void uploadFilesInFolder(final File folder, final String uploadFolder, final IProgressMonitor monitor) throws NXCException, IOException 
-   {
-      for(final File fileEntry : folder.listFiles())
-      {
-          if (fileEntry.isDirectory()) 
-          {
-             session.createFolderOnAgent(objectId, uploadFolder + "/" + fileEntry.getName()); //$NON-NLS-1$
-             uploadFilesInFolder(fileEntry, uploadFolder + "/" + fileEntry.getName(), monitor); //$NON-NLS-1$
-          } 
-          else 
-          {
-             session.uploadLocalFileToAgent(objectId, fileEntry, uploadFolder + "/" + fileEntry.getName(), new ProgressListener() { //$NON-NLS-1$
-                private long prevWorkDone = 0;
-
-                @Override
-                public void setTotalWorkAmount(long workTotal)
-                {
-                   monitor.beginTask(Messages.get().UploadFileToServer_TaskNamePrefix + fileEntry.getAbsolutePath(),
-                         (int)workTotal);
-                }
-
-                @Override
-                public void markProgress(long workDone)
-                {
-                   monitor.worked((int)(workDone - prevWorkDone));
-                   prevWorkDone = workDone;
-                }
-             });
-             monitor.done(); 
-          }
-      }
-  }
 
    /**
     * Delete selected file
@@ -1052,7 +1016,7 @@ public class AgentFileManager extends ViewPart
             @Override
             protected void runInternal(final IProgressMonitor monitor) throws Exception
             {
-                               //create zip from download folder wile download
+               //create zip from download folder wile download
                long dirSize = -1;
                try
                {
@@ -1064,12 +1028,12 @@ public class AgentFileManager extends ViewPart
                monitor.beginTask(String.format("Downloading directory %s", sf.getName()), (int)dirSize);
                
                final File zipFile = File.createTempFile("download_", ".zip");
-                               FileOutputStream fos = new FileOutputStream(zipFile);
-                               ZipOutputStream zos = new ZipOutputStream(fos);
-                               downloadDir(sf, sf.getName(), zos, monitor);
-                               zos.close();
-                               fos.close();
-                               
+               FileOutputStream fos = new FileOutputStream(zipFile);
+               ZipOutputStream zos = new ZipOutputStream(fos);
+               downloadDir(sf, sf.getName(), zos, monitor);
+               zos.close();
+               fos.close();
+               
                DownloadServiceHandler.addDownload(zipFile.getName(), sf.getName() + ".zip", zipFile, "application/octet-stream");
                runInUIThread(new Runnable() {
                   @Override
@@ -1216,19 +1180,36 @@ public class AgentFileManager extends ViewPart
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
          {
-            session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName()); //$NON-NLS-1$
+            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(object.getType(), object.getName(), true, true, false) {
+               
+               @Override
+               public void executeAction() throws NXCException, IOException
+               {
+                  session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false); //$NON-NLS-1$
+               }
 
-            runInUIThread(new Runnable() {
                @Override
-               public void run()
+               public void executeSameFunctionWithOverwrite() throws IOException, NXCException
                {
-                  object.getParent().removeChield(object);
-                  viewer.refresh(object.getParent(), true);
-                  object.setParent(target);
-                  target.addChield(object);
-                  viewer.refresh(object.getParent(), true);
+                  session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), true); //$NON-NLS-1$                  
                }
-            });
+            };
+            verify.run(viewer.getControl().getDisplay());
+            
+            if(verify.isOkPressed())
+            {
+               runInUIThread(new Runnable() {
+                  @Override
+                  public void run()
+                  {
+                     object.getParent().removeChield(object);
+                     viewer.refresh(object.getParent(), true);
+                     object.setParent(target);
+                     target.addChield(object);
+                     viewer.refresh(object.getParent(), true);
+                  }
+               });
+            }
          }
       }.start();
    }
@@ -1261,8 +1242,22 @@ public class AgentFileManager extends ViewPart
 
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
-         {
-            session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder); //$NON-NLS-1$
+         { 
+            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, newFolder, true, true, false) {
+               
+               @Override
+               public void executeAction() throws NXCException, IOException
+               {
+                  session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder, false); //$NON-NLS-1$
+               }
+   
+               @Override
+               public void executeSameFunctionWithOverwrite() throws IOException, NXCException
+               {
+                  session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder, true); //$NON-NLS-1$             
+               }
+            };
+            verify.run(viewer.getControl().getDisplay());
             parentFolder.setChildren(session.listAgentFiles(parentFolder, parentFolder.getFullName(), objectId));
 
             runInUIThread(new Runnable() {
@@ -1340,7 +1335,10 @@ public class AgentFileManager extends ViewPart
       if( executor != null ) 
       {
          StringBuilder js = new StringBuilder();
-         js.append("copyTextToClipboard(\'" + filePath.substring(1, filePath.length()) + "\');"); // Substring is made to remove first "/"
+         filePath = filePath.replace("\\\\", "\\");
+         filePath = filePath.replace("\\", "\\\\");
+         filePath = filePath.replace("//", "/"); 
+         js.append("copyTextToClipboard(\'" + filePath + "\');"); // Substring is made to remove first "/"
          executor.execute(js.toString());
       }
    }
@@ -1388,4 +1386,102 @@ public class AgentFileManager extends ViewPart
       filter.setFilterString(text);
       viewer.refresh(false);
    }
+   
+   /**
+    * Nested class that check if file already exist and it should be overwritten
+    *
+    */
+   abstract class NestedVerifyOverwrite
+   {
+      private boolean okPresseed;
+      private int type;
+      private String name;
+      private boolean askFolderOverwrite;
+      private boolean askFileOverwrite;
+      private boolean overwrite;
+      
+      public NestedVerifyOverwrite(int fileType, String fileName, boolean askFolderOverwrite, boolean askFileOverwrite, boolean overwrite)
+      {
+         type = fileType;
+         name = fileName;
+         this.askFolderOverwrite = askFolderOverwrite;
+         this.askFileOverwrite = askFileOverwrite;
+         this.overwrite = overwrite;
+         okPresseed = true;
+      }
+      
+      public boolean askFolderOverwrite()
+      {
+         return askFolderOverwrite;
+      }
+      
+      public boolean askFileOverwrite()
+      {
+         return askFileOverwrite;
+      }
+      
+      public void run(Display disp) throws IOException, NXCException
+      {         
+         try
+         {
+            executeAction();
+         }
+         catch(final NXCException e)
+         {
+            if(e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST || type == AgentFile.DIRECTORY)
+            {
+               if(askFolderOverwrite)
+               {
+                  disp.syncExec(new Runnable() {
+                     @Override
+                     public void run()
+                     {
+                        DialogData data = MessageDialogHelper.openOneButtonWarningWithCheckbox(getSite().getShell(), 
+                              String.format("%s already exist", e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File"), 
+                              "Do not show again for this upload", String.format("%s %s already exist",e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File", name));
+                        askFolderOverwrite = !data.getSaveSelection();
+                        okPresseed = false;
+                     }
+                  });
+               }
+            }   
+            else if(e.getErrorCode() == RCC.FILE_ALREADY_EXISTS ||  e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST)
+            {
+               if(askFileOverwrite)
+               {
+                  disp.syncExec(new Runnable() {
+                     @Override
+                     public void run()
+                     {
+   
+                        DialogData data = MessageDialogHelper.openWarningWithCheckbox(getSite().getShell(), 
+                              String.format("%s overwrite confirmation", type == AgentFile.DIRECTORY ? "Folder" : "File"), 
+                              "Save chose for current upload files",
+                              String.format("%s with %s name already exists. Are you sure you want to overwrite it?", e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File", name));
+                        askFileOverwrite = !data.getSaveSelection();
+                        okPresseed = data.isOkPressed();                           
+                     }
+                  });
+                  if(okPresseed)                     
+                     executeSameFunctionWithOverwrite();
+               }
+               else
+               {
+                  if(overwrite)
+                  {
+                     executeSameFunctionWithOverwrite();
+                  }
+               }
+            }
+            else
+               throw e;
+         }
+      }
+      public boolean isOkPressed()
+      {
+         return okPresseed;
+      }
+      public abstract void executeAction() throws NXCException, IOException;
+      public abstract void executeSameFunctionWithOverwrite() throws NXCException, IOException;
+   }
 }
index b73afb1..78c3abb 100644 (file)
@@ -28,7 +28,7 @@ import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.SWT;
-import org.netxms.client.MacAddress;
+import org.netxms.base.MacAddress;
 import org.netxms.client.datacollection.DciValue;
 import org.netxms.client.maps.elements.NetworkMapObject;
 import org.netxms.client.objects.Node;
index 744a828..64c8b30 100644 (file)
@@ -28,7 +28,7 @@ import org.eclipse.draw2d.text.FlowPage;
 import org.eclipse.draw2d.text.TextFlow;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.SWT;
-import org.netxms.client.MacAddress;
+import org.netxms.base.MacAddress;
 import org.netxms.client.constants.ObjectStatus;
 import org.netxms.client.datacollection.DciValue;
 import org.netxms.client.datacollection.GraphItem;
index ea1d7c2..44ae60a 100644 (file)
@@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 import org.netxms.base.InetAddressEx;
-import org.netxms.client.MacAddress;
+import org.netxms.base.MacAddress;
 import org.netxms.ui.eclipse.objectmanager.Messages;
 import org.netxms.ui.eclipse.tools.IPAddressValidator;
 import org.netxms.ui.eclipse.tools.IPNetMaskValidator;
index a5b149b..d943872 100644 (file)
@@ -26,8 +26,8 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
-import org.netxms.client.MacAddress;
-import org.netxms.client.MacAddressFormatException;
+import org.netxms.base.MacAddress;
+import org.netxms.base.MacAddressFormatException;
 import org.netxms.client.objects.Node;
 import org.netxms.client.objects.Sensor;
 import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
index c09723a..61f0c95 100644 (file)
@@ -24,7 +24,7 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.window.Window;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.netxms.client.MacAddress;
+import org.netxms.base.MacAddress;
 import org.netxms.client.NXCSession;
 import org.netxms.client.topology.ConnectionPoint;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
index 296db4e..dad145c 100644 (file)
@@ -25,8 +25,8 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
-import org.netxms.client.MacAddress;
-import org.netxms.client.MacAddressFormatException;
+import org.netxms.base.MacAddress;
+import org.netxms.base.MacAddressFormatException;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 import org.netxms.ui.eclipse.topology.Messages;