# Buggy code
def run(self):
    if not self.skip_git_actions and not self.git.is_ready_to_go():
        return 1

    data_dir_path = self.get_not_existing_dir(self.parsed_args.data_dir)
    cache_dir_path = self.get_not_existing_dir(self.parsed_args.cache_dir)
    state_dir_path = self.get_not_existing_dir(self.parsed_args.state_dir)

    conf_file_name = self.get_not_existing_conf_file_name()

    data_dir_path.mkdir()
    cache_dir_path.mkdir()
    state_dir_path.mkdir()
    Logger.info(
        "Directories {}/, {}/ and {}/ were created".format(
            data_dir_path.name, cache_dir_path.name, state_dir_path.name
        )
    )

    conf_file = open(conf_file_name, "wt")
    conf_file.write(
        self.CONFIG_TEMPLATE.format(
            data_dir_path.name, cache_dir_path.name, state_dir_path.name
        )
    )
    conf_file.close()

    self.modify_gitignore(cache_dir_path.name)

    message = "DVC init. data dir {}, cache dir {}, state dir {}".format(
        data_dir_path.name, cache_dir_path.name, state_dir_path.name
    )
    return self.commit_if_needed(message)


# Traceback (OSError)
$ dvc data-sync data/summary.txt
Downloading cache file from S3 "nlx-shared/tag_classifier/.cache/summary.txt_6405e23"
Traceback (most recent call last):
File "/Users/dmitry/src/dvc/dvc2.py", line 77, in <module>
Runtime.run(CmdDataSync, args_start_loc=argv_offset)
File "/Users/dmitry/src/dvc/dvc/runtime.py", line 45, in run
sys.exit(instance.run())
File "/Users/dmitry/src/dvc/dvc/command/data_sync.py", line 60, in run
return self.sync_symlink(data_item)
File "/Users/dmitry/src/dvc/dvc/command/data_sync.py", line 84, in sync_symlink
self.sync_from_cloud(data_item)
File "/Users/dmitry/src/dvc/dvc/command/data_sync.py", line 184, in sync_from_cloud
return self._sync_from_cloud_aws(item)
File "/Users/dmitry/src/dvc/dvc/command/data_sync.py", line 106, in _sync_from_cloud_aws
key.get_contents_to_filename(item.resolved_cache.relative, cb=percent_cb)
File "/usr/local/lib/python2.7/site-packages/boto/s3/key.py", line 1714, in get_contents_to_filename
os.remove(filename)
OSError: [Errno 2] No such file or directory: '.cache/summary.txt_6405e23'

# Fixed code
def run(self):
    if not self.skip_git_actions and not self.git.is_ready_to_go():
        return 1

    data_dir_path = self.get_not_existing_dir(self.parsed_args.data_dir)
    cache_dir_path = self.get_not_existing_dir(self.parsed_args.cache_dir)
    state_dir_path = self.get_not_existing_dir(self.parsed_args.state_dir)

    conf_file_name = self.get_not_existing_conf_file_name()

    data_dir_path.mkdir()
    cache_dir_path.mkdir()
    state_dir_path.mkdir()
    Logger.info(
        "Directories {}/, {}/ and {}/ were created".format(
            data_dir_path.name, cache_dir_path.name, state_dir_path.name
        )
    )

    data_empty_file = os.path.join(self.parsed_args.data_dir, self.EMPTY_FILE_NAME)
    cache_empty_file = os.path.join(self.parsed_args.cache_dir, self.EMPTY_FILE_NAME)
    state_empty_file = os.path.join(self.parsed_args.state_dir, self.EMPTY_FILE_NAME)

    open(data_empty_file, "w").close()
    open(cache_empty_file, "w").close()
    open(state_empty_file, "w").close()

    Logger.info(
        "Empty files {}, {} and {} were created".format(
            data_empty_file, cache_empty_file, state_empty_file
        )
    )

    conf_file = open(conf_file_name, "wt")
    conf_file.write(
        self.CONFIG_TEMPLATE.format(
            data_dir_path.name, cache_dir_path.name, state_dir_path.name
        )
    )
    conf_file.close()

    message = "DVC init. data dir {}, cache dir {}, state dir {}".format(
        data_dir_path.name, cache_dir_path.name, state_dir_path.name
    )
    if self.commit_if_needed(message) == 1:
        return 1

    self.modify_gitignore(cache_dir_path.name)
    return self.commit_if_needed("DVC init. Commit .gitignore file")