import path from 'path'
import extend from 'extend'

import {
  abeExtend,
  Manager,
  config,
  coreUtils,
  cmsData,
  cmsOperations
} from '../../'

const duplicate = function(oldPostUrl, template, newPath, name, req, isUpdate = false) {
  const p = new Promise((resolve, reject) => {
    abeExtend.hooks.instance.trigger('beforeDuplicate', oldPostUrl, template, newPath, name, req, isUpdate)

    let json = {}
    let revisions = []
    const newPostUrl = path.join(newPath, coreUtils.slug.clean(name))
    if(oldPostUrl != null) {
      const files = Manager.instance.getList()
      const oldPostDataPath = path.join(config.root, config.data.url, oldPostUrl.replace('.' + config.files.templates.extension, '.json'))
      let posts = []
      posts = coreUtils.array.filter(files, 'path', oldPostDataPath)

      if(posts.length > 0 && posts[0].revisions != null) {
        revisions = posts[0].revisions
        if(revisions != null && revisions[0] != null) {
          json = cmsData.file.get(revisions[0].path)
          json = extend(true, json, req.body)

          delete json.abe_meta
        }
      }
    }

    abeExtend.hooks.instance.trigger('afterDuplicate', json, oldPostUrl, template, newPath, name, req, isUpdate)

    var pCreate = cmsOperations.create(template, newPath, name, req, json, (isUpdate) ? false : true)
    pCreate.then((resSave) => {
      if (isUpdate && oldPostUrl !== path.join('/', newPostUrl)) {
        abeExtend.hooks.instance.trigger('beforeUpdate', json, oldPostUrl, template, newPath, name, req, isUpdate)
        cmsOperations.remove.remove(oldPostUrl)
      }
      resolve(resSave)
    },
    () => {
      reject()
    }).catch(function(e) {
      console.error('[ERROR] abe-duplicate.js', e)
      reject()
    })
  })

  return p
}

export default duplicate
@@ -17,16 +17,38 @@
  'path'%0A
+import url from 'url'%0A
 import e
@@ -477,25 +477,27 @@
 stUrl = 
-path.join
+url.resolve
 (newPath
@@ -1427,25 +1427,27 @@
 Url !== 
-path.join
+url.resolve
 ('/', ne

fix : update error under windows in specific conditions