             callback()
 
         else
-            parent   = path.resolve @path, doc.path
+            tmpFile  = path.join @tmpPath, doc.path
+            parent   = path.resolve @basePath, doc.path
             filePath = path.join parent, doc.name
             binaryId = doc.binary.file.id
             checksum = doc.binary.file.checksum
 
             async.waterfall [
-                # Ensure that the parent directory is created
-                (next) ->
-                    fs.ensureDir parent, next
+                (next) =>
+                    fs.ensureDir @tmpPath, next
 
-                # Check if a file with the same checksum exists
                 (res, next) ->
                     filesystem.fileExistsLocally checksum, next
 
-                # If a similar file exists, we just have to copy it
-                # Otherwise download the binary from CouchDB
                 (existingFilePath, next) =>
                     if existingFilePath
                         stream = fs.createReadStream existingFilePath

                    else
                        @other.createReadStream doc, next

                # Write the file
                # TODO verify the checksum -> remove file if not ok
                # TODO show progress
                (stream, next) ->
                    target = fs.createWriteStream filePath
                    stream.pipe target
                    stream.on 'end', next

                # Change utimes (creation and modification date)
                (next) ->
                    lastModification = new Date doc.lastModification
                    fs.utimes filePath, new Date(), lastModification, next
            ], callback


    createFolder: (doc, callback) =>

    # Remote-to-local operations
    #
    # Steps:
    # * Checks if the doc is valid: has a path and a name
    # * Ensure that the temporary directory exists
    # * Try to find a similar file based on his checksum
    #   (in that case, it just requires a local copy)
    # * Download the linked binary from remote
    # * Write to a temporary file
    # * Ensure parent folder exists
    # * Move the temporay file to its final destination
    # * Update creation and last modification dates
    #
    createFile: (doc, callback) =>
