Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--keep-files works now but the temporary directory won't get removed #73

Closed
mikelei8291 opened this issue Oct 24, 2022 · 2 comments · Fixed by #87
Closed

--keep-files works now but the temporary directory won't get removed #73

mikelei8291 opened this issue Oct 24, 2022 · 2 comments · Fixed by #87
Assignees
Labels
bug Something isn't working

Comments

@mikelei8291
Copy link
Contributor

Describe the bug
After fixing #71 in commit 7fad013, a new bug was introduced that the files in the temporary directory will be removed but not the directory itself if --keep-files was NOT used.

To Reproduce
twspace_dl --input-cookie-file twitter.txt -suU "https://twitter.com/username" -m -v

Expected behavior
Temporary directories and their content got removed after running the command when --keep-files was not used.

Output
Screenshot

Desktop (please complete the following information):

  • OS: Ubuntu Linux 22.04.1 LTS
  • twspace-dl Version: 6c57161
  • Installation method: pip from GitHub repo
@mikelei8291 mikelei8291 added the bug Something isn't working label Oct 24, 2022
@Ryu1845
Copy link
Collaborator

Ryu1845 commented Oct 24, 2022

I'll investigate, I don't see where the bug is at first glance

@mikelei8291
Copy link
Contributor Author

OK I got it, it was because I used the -s (--skip-download) option.

Before 7c309c0 the function call tempfile.mkdtemp(dir=".") was done in the download() method of the TwspaceDL class:

tempdir = self._tmpdir = tempfile.mkdtemp(dir=".")

So when the -s option was used the temp directory was not actually created at all, as the download() method would only be called if the -s option was not specified:

if not args.skip_download:
try:
twspace_dl.download()

However, they made a mistake in 7c309c0 that the call to tempfile.TemporaryDirectory(dir=".") was done in the constructor of the TwspaceDL class, thus creating an empty temp directory every time the class was instantiated. After fixing #71, you only changed the function call in the constructor back to tempfile.mkdtemp(dir="."), but the directory won't get removed by the shutil.rmtree(twspace_dl.tempdir) call as the condition to the if statement would be False when the -s option was specified.

if not args.skip_download:
try:
twspace_dl.download()
except KeyboardInterrupt:
logging.info("Download Interrupted by user")
finally:
if not args.keep_files and os.path.exists(twspace_dl.tempdir):
shutil.rmtree(twspace_dl.tempdir)

Therefore, I would suggest to revert back the changes done in 7c309c0, especially L102 in twspace_dl/twspace_dl.py to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants