paradoxxxzero / atom-python-import-magic

Import automatically python modules using importmagic
MIT License
4 stars 2 forks source link

Error when re-indexing by saving and by shortcut. #9

Open DeadSix27 opened 5 years ago

DeadSix27 commented 5 years ago

Hey, I've encountered this error (see bottom) consistently when reindexing.

I guess it creates the .tmp file first but then forgets to remove the original when trying to rename the .tmp file.

I fixed the issue by making it delete the old index file before renaming the tmp file:

https://github.com/paradoxxxzero/atom-python-import-magic/blob/master/lib/import_magic_interface.py#L110

I changed:

        if os.path.exists(self._tmp_index_file):
            os.rename(self._tmp_index_file, self.index_file)

to

        if os.path.exists(self._tmp_index_file):
            if os.path.isfile(self.index_file):
                os.unlink(self.index_file)
            os.rename(self._tmp_index_file, self.index_file)

If this solution is appropriate I can submit a PR for it, just say so then.

Error:

Python Import Magic Invocation Error
Traceback (most recent call last):
  File "C:\Users\mainpcuser\.atom\packages\python-import-magic\lib/import_magic_interface.py", line 167, in <module>
    Commands().run()
  File "C:\Users\mainpcuser\.atom\packages\python-import-magic\lib/import_magic_interface.py", line 98, in run
    fun(**self.data)
  File "C:\Users\mainpcuser\.atom\packages\python-import-magic\lib/import_magic_interface.py", line 121, in reindex
    self.create_index()
  File "C:\Users\mainpcuser\.atom\packages\python-import-magic\lib/import_magic_interface.py", line 111, in create_index
    os.rename(self._tmp_index_file, self.index_file)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'K:\\some_folder\\.magicindex.json.tmp' -> 'K:\\some_folder\\.magicindex.json'