# Buggy code
def create(cls, jobStore, leaderPath):
    """
    Saves the content of the file or directory at the given path to the given job store
    and returns a resource object representing that content for the purpose of obtaining it
    again at a generic, public URL. This method should be invoked on the leader node.

    :rtype: Resource
    """
    pathHash = cls._pathHash(leaderPath)
    contentHash = hashlib.md5()
    # noinspection PyProtectedMember
    with cls._load(leaderPath) as src:
        with jobStore.writeSharedFileStream(
            sharedFileName=pathHash, isProtected=False
        ) as dst:
            userScript = src.read()
            contentHash.update(userScript)
            dst.write(userScript)
    return cls(
        name=os.path.basename(leaderPath),
        pathHash=pathHash,
        url=jobStore.getSharedPublicUrl(sharedFileName=pathHash),
        contentHash=contentHash.hexdigest(),
    )


# Traceback (HTTPError)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:    ---TOIL WORKER OUTPUT LOG---
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:    Traceback (most recent call last):
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/worker.py", line 266, in main
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        job = Job._loadJob(jobWrapper.command, jobStore)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/job.py", line 937, in _loadJob
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        userModule = cls._loadUserModule(userModule)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/job.py", line 908, in _loadUserModule
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        userModule = userModule.localize()
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/resource.py", line 416, in localize
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        resource.download(callback=stash)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/resource.py", line 152, in download
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        self._save(tempDirPath)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/resource.py", line 269, in _save
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        self._download(bytesIO)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/local/lib/python2.7/dist-packages/toil/resource.py", line 223, in _download
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        with closing(urlopen(self.url)) as content:
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        return opener.open(url, data, timeout)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/lib/python2.7/urllib2.py", line 437, in open
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        response = meth(req, response)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        'http', request, response, code, msg, hdrs)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/lib/python2.7/urllib2.py", line 475, in error
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        return self._call_chain(*args)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        result = func(*args)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:      File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:    HTTPError: HTTP Error 400: Bad Request
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:    Exiting the worker because of a failed jobWrapper on host ip-172-31-45-12
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:    ERROR:toil.worker:Exiting the worker because of a failed jobWrapper on host ip-172-31-45-12
WARNING:toil.leader:e8f55793-15ca-471a-947f-38936f917bba:    WARNING:toil.jobWrapper:Due to failure we are reducing the remaining retry count of job e8f55793-15ca-471a-947f-38936f917bba to 2

# Fixed code
def create(cls, jobStore, leaderPath):
    """
    Saves the content of the file or directory at the given path to the given job store
    and returns a resource object representing that content for the purpose of obtaining it
    again at a generic, public URL. This method should be invoked on the leader node.

    :param toil.jobStores.abstractJobStore.AbstractJobStore jobStore:

    :param str leaderPath:

    :rtype: Resource
    """
    pathHash = cls._pathHash(leaderPath)
    contentHash = hashlib.md5()
    # noinspection PyProtectedMember
    with cls._load(leaderPath) as src:
        with jobStore.writeSharedFileStream(
            sharedFileName=pathHash, isProtected=False
        ) as dst:
            userScript = src.read()
            contentHash.update(userScript)
            dst.write(userScript)
    return cls(
        name=os.path.basename(leaderPath),
        pathHash=pathHash,
        url=jobStore.getSharedPublicUrl(sharedFileName=pathHash),
        contentHash=contentHash.hexdigest(),
    )