 cp = require 'child_process'
 path = require 'path'
 
-
-lazyCopyFile = (source, target, callback) ->
-  if fs.existsSync target
-    tstat = fs.statSync target
-    sstat = fs.statSync source
-    if tstat.mtime.value < sstat.mtime.value
-      reader = fs.createReadStream source
-      writer = fs.createWriteStream target
-      writer.on 'close', callback
-      writer.on 'error', callback
-      reader.pipe writer
-      return
-  callback()
-
-exec_promise = (func, args...) ->
+execPromise = (func, args...) ->
   new Promise((resolve, reject) ->
     nargs = args.concat( (errors...) ->
       if errors[0] == null

        resolve()
    ).then( ->
      grunt.log.writeln 'migrating...'
      exec_promise cp.exec, 'python3 manage.py migrate', null
    ).then( ->
      grunt.log.writeln 'loading sample data...'
      exec_promise cp.exec, 'python3 manage.py loaddata courses', null
    ).then( ->
      done()
    ).catch((error) ->


    success = true

    queue = queue.map ([source, dest]) ->
      [path.normalize(path.join(base, source)), path.normalize(path.join(target, dest))]

    for [source, dest] in queue
      grunt.log.writeln source, '->', dest
      dir = path.dirname(dest)
      if not fs.existsSync(dir)
        grunt.log.writeln true
        mkTree dir
      if not fs.existsSync(dir)
        callback(false)
      lazyCopyFile source, target, (err) ->
        if err != undefined
          success = false
          grunt.log.writeln err
