     dirLastModification = stats.mtime
 
     # Lookup for existing directory
-    db.db.query { map: (doc) ->
-
-        if doc.docType is 'Folder'
-            emit doc._id, doc
-
-    }, (err, res) ->
+    db.db.query { map: (doc) -> emit doc._id, doc if doc.docType is 'Folder' }, (err, res) ->
         for doc in res.rows
             doc = doc.value
             if doc.path is dirPath and doc.name is dirName

    putDirectory devicename, ".#{filePath}", false, (err, res) ->

        # Fetch only files with the same path/filename
        db.db.query { map: (doc) ->

            if doc.docType is 'File'
                emit doc._id, doc

        }, (err, res) ->
            for doc in res.rows
                doc = doc.value
                if doc.name is fileName and doc.path is filePath

    buildFsTree devicename, { filePath: filePath }, (err, res) ->

        # Fetch only files
        db.db.query { map: (doc) -> emit doc._id, doc if doc.docType is 'File' }, (err, res) ->
            async.each res.rows, (doc, callback) ->
                doc = doc.value
                if (not filePath? or filePath is path.join doc.path, doc.name) and doc.binary?
                    binaryPath = path.join remoteConfig.path, doc.path, doc.name
                    binaryUri = "cozy/#{doc.binary.file.id}/file"
                    # Fetch binary via CouchDB API
                    client.saveFile binaryUri, binaryPath, (err, res, body) ->
                        console.log err if err

                        # Rebuild FS Tree to correct utime
                        buildFsTree devicename, { filePath: path.join doc.path, doc.name }, callback
                else
                    callback()
            , callback


putDirectory = (devicename, directoryPath, recursive, callback) ->
