Skip to content

Commit cc17a87

Browse files
Delete pdf/epub artifacts when their build is disabled
The reason for this is that old versions which had PDF builds in the past and for which the PDF builds have been disabled will keep the stale PDF of old builds lying around. We need to delete the artifacts if they exist and are disabled for the current build. Addresses #1431 (comment)
1 parent 5695f78 commit cc17a87

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

readthedocs/projects/tasks.py

+30
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ def finish_build(version_pk, build_pk, hostname=None, html=False,
621621
version.built = True
622622
version.save()
623623

624+
if not pdf:
625+
clear_pdf_artifacts(version)
626+
if not epub:
627+
clear_epub_artifacts(version)
628+
624629
move_files(
625630
version_pk=version_pk,
626631
hostname=hostname,
@@ -661,19 +666,28 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False,
661666
from_path = version.project.artifact_path(version=version.slug, type='sphinx_localmedia')
662667
to_path = version.project.get_production_media_path(type='htmlzip', version_slug=version.slug, include_file=False)
663668
Syncer.copy(from_path, to_path, host=hostname)
669+
664670
if search:
665671
from_path = version.project.artifact_path(version=version.slug, type='sphinx_search')
666672
to_path = version.project.get_production_media_path(type='json', version_slug=version.slug, include_file=False)
667673
Syncer.copy(from_path, to_path, host=hostname)
674+
668675
# Always move PDF's because the return code lies.
669676
if pdf:
670677
from_path = version.project.artifact_path(version=version.slug, type='sphinx_pdf')
671678
to_path = version.project.get_production_media_path(type='pdf', version_slug=version.slug, include_file=False)
672679
Syncer.copy(from_path, to_path, host=hostname)
680+
elif not version.project.enable_pdf_build:
681+
to_path = version.project.get_production_media_path(type='pdf', version_slug=version.slug, include_file=False)
682+
Syncer.remove(to_path)
683+
673684
if epub:
674685
from_path = version.project.artifact_path(version=version.slug, type='sphinx_epub')
675686
to_path = version.project.get_production_media_path(type='epub', version_slug=version.slug, include_file=False)
676687
Syncer.copy(from_path, to_path, host=hostname)
688+
elif not version.project.enable_epub_build:
689+
to_path = version.project.get_production_media_path(type='epub', version_slug=version.slug, include_file=False)
690+
Syncer.remove(to_path)
677691

678692
if 'mkdocs' in version.project.documentation_type:
679693
if search:
@@ -882,7 +896,23 @@ def remove_dir(path):
882896
def clear_artifacts(version_pk):
883897
""" Remove artifacts from the web servers. """
884898
version = Version.objects.get(pk=version_pk)
899+
clear_pdf_artifacts(version)
900+
clear_epub_artifacts(version)
901+
clear_htmlzip_artifacts(version)
902+
clear_html_artifacts(version)
903+
904+
905+
def clear_pdf_artifacts(version):
885906
run_on_app_servers('rm -rf %s' % version.project.get_production_media_path(type='pdf', version_slug=version.slug))
907+
908+
909+
def clear_epub_artifacts(version):
886910
run_on_app_servers('rm -rf %s' % version.project.get_production_media_path(type='epub', version_slug=version.slug))
911+
912+
913+
def clear_htmlzip_artifacts(version):
887914
run_on_app_servers('rm -rf %s' % version.project.get_production_media_path(type='htmlzip', version_slug=version.slug))
915+
916+
917+
def clear_html_artifacts(version):
888918
run_on_app_servers('rm -rf %s' % version.project.rtd_build_path(version=version.slug))

0 commit comments

Comments
 (0)