                         if err
                             c(err)
                         else
-                            mesg.path = realpath
+                            path = realpath
                             c()
-                (c) ->
-                    fs.writeFile(path, value.blob, c)
                 (c) ->
                     getuid user, (err, id) ->
                         if err

            socket.write_mesg 'json', message.error(id:mesg.id, error:err)
    )

# Write a file to the project
events.write_file_to_project = (socket, mesg) ->
    data_uuid = mesg.data_uuid

                        else
                            uid = id
                            c()
                (c) ->
                    ensure_containing_directory_exists(mesg.project_id, uid, path, c)
                (c) ->
                    fs.writeFile(path, value.blob, c)
                # Set the permissions on the file to the correct user (instead of root)
                (c) ->
                    fs.chown(path, uid, uid, c)
