@@ -1262,13 +1262,22 @@ public JContainer CopyCommand(dynamic cmd)
12621262 VolumeObjectTO destVolumeObjectTO = VolumeObjectTO . ParseJson ( cmd . destTO ) ;
12631263
12641264 string destFile = null ;
1265- if ( destTemplateObjectTO != null && destTemplateObjectTO . primaryDataStore != null )
1265+ if ( destTemplateObjectTO != null )
12661266 {
1267- destFile = destTemplateObjectTO . FullFileName ;
1268- if ( ! destTemplateObjectTO . primaryDataStore . isLocal )
1267+ if ( destTemplateObjectTO . primaryDataStore != null )
12691268 {
1270- PrimaryDataStoreTO primary = destTemplateObjectTO . primaryDataStore ;
1271- Utils . ConnectToRemote ( primary . UncPath , primary . Domain , primary . User , primary . Password ) ;
1269+ destFile = destTemplateObjectTO . FullFileName ;
1270+ if ( ! destTemplateObjectTO . primaryDataStore . isLocal )
1271+ {
1272+ PrimaryDataStoreTO primary = destTemplateObjectTO . primaryDataStore ;
1273+ Utils . ConnectToRemote ( primary . UncPath , primary . Domain , primary . User , primary . Password ) ;
1274+ }
1275+ }
1276+ else if ( destTemplateObjectTO . nfsDataStoreTO != null )
1277+ {
1278+ destFile = destTemplateObjectTO . FullFileName ;
1279+ NFSTO store = destTemplateObjectTO . nfsDataStoreTO ;
1280+ Utils . ConnectToRemote ( store . UncPath , store . Domain , store . User , store . Password ) ;
12721281 }
12731282 }
12741283
@@ -1428,6 +1437,38 @@ public JContainer CopyCommand(dynamic cmd)
14281437 result = true ;
14291438 }
14301439 }
1440+ else if ( srcVolumeObjectTO != null && destTemplateObjectTO != null )
1441+ {
1442+ var guessedDestFile = destTemplateObjectTO . FullFileName ;
1443+ if ( File . Exists ( guessedDestFile ) )
1444+ {
1445+ logger . Info ( "Deleting existing file " + guessedDestFile ) ;
1446+ File . Delete ( guessedDestFile ) ;
1447+ }
1448+
1449+ destTemplateObjectTO . format = srcVolumeObjectTO . format ;
1450+ destFile = destTemplateObjectTO . FullFileName ;
1451+ if ( File . Exists ( destFile ) )
1452+ {
1453+ logger . Info ( "Deleting existing file " + destFile ) ;
1454+ File . Delete ( destFile ) ;
1455+ }
1456+
1457+ string srcFile = srcVolumeObjectTO . FullFileName ;
1458+ if ( ! File . Exists ( srcFile ) )
1459+ {
1460+ details = "Local template file missing from " + srcFile ;
1461+ }
1462+ else
1463+ {
1464+ // Create the directory before copying the files. CreateDirectory
1465+ // doesn't do anything if the directory is already present.
1466+ Directory . CreateDirectory ( Path . GetDirectoryName ( destFile ) ) ;
1467+ File . Copy ( srcFile , destFile ) ;
1468+ newData = cmd . destTO ;
1469+ result = true ;
1470+ }
1471+ }
14311472 else
14321473 {
14331474 details = "Data store combination not supported" ;
0 commit comments