 fs = require 'fs'
+path = require 'path'
 request = require 'request-json'
 PouchDB = require 'pouchdb'
 mkdirp = require 'mkdirp'


        for doc in res.rows
            # Fetch every binary
            filePath = remoteConfig.path + doc.value.path + '/' + doc.value.name
            if doc.value.binary?
                binaryUri = 'cozy/' + doc.value.binary.file.id + '/file'
                client.saveFile binaryUri, filePath, (err, res, body) ->
                    if err
                        console.log err


runSync = (devicename) ->


    db.db.query { map: map }, (err, res) ->
        for doc in res.rows
            name = path.join remoteConfig.path, doc.value.path, doc.value.name
            if doc.value.docType is 'Folder'
                # Create folder
                mkdirp.sync name
                fs.utimesSync name,
                    new Date(doc.value.creationDate),
                    new Date(doc.value.lastModification)
            else
                # Create parent folder and touch file
                mkdirp.sync path.join remoteConfig.path, doc.value.path
                touch name
                fs.utimesSync name,
                    new Date(doc.value.creationDate),
                    new Date(doc.value.lastModification)


fetchBinaries = (devicename) ->
