 
 
           os.mkdir TEMP_DIR
-          fd = fs.openSync(LOCATIONS_TEMP_FILE, 'w')
+          fd = fs.openSync(PATH + LOCATIONS_TEMP_FILE, 'w')
           for r in result.rows
             fs.writeSync fd, JSON.stringify(r) + "\n"
           fs.closeSync fd

      console.warn "> There was an error: " + err
    else
      console.log("> All tasks finished")
    
    mongodb.close()
    pgclient.end()

        callWhenEnded()











  (callWhenEnded) ->
    console.log "> Ensure aiddata commitments indices"
    
    indices = [
      { aiddata_id : 1 }
      { origin : 1 }
      { dest : 1 }
      { origin : 1, dest : 1 }
      { coalesced_purpose_code : 1 }
    ]
    ensureIndices 'aiddata', indices, callWhenEnded



  (callWhenEnded) ->
    console.log "> Ensure locations indices"    
    indices = [
      { code : 1 }
    ]
    ensureIndices 'locations', indices, callWhenEnded



