@@ -741,6 +741,8 @@ def update_app_instances(
741
741
)
742
742
hostname = socket .gethostname ()
743
743
744
+ delete_unsynced_media = True
745
+
744
746
if getattr (storage , 'write_build_media' , False ):
745
747
# Handle the case where we want to upload some built assets to our storage
746
748
move_files .delay (
@@ -752,11 +754,13 @@ def update_app_instances(
752
754
localmedia = localmedia ,
753
755
pdf = pdf ,
754
756
epub = epub ,
757
+ delete_unsynced_media = delete_unsynced_media ,
755
758
)
756
759
# Set variables so they don't get synced in the next broadcast step
757
760
localmedia = False
758
761
pdf = False
759
762
epub = False
763
+ delete_unsynced_media = False
760
764
761
765
# Broadcast finalization steps to web application instances
762
766
broadcast (
@@ -774,6 +778,7 @@ def update_app_instances(
774
778
search = search ,
775
779
pdf = pdf ,
776
780
epub = epub ,
781
+ delete_unsynced_media = delete_unsynced_media ,
777
782
),
778
783
callback = sync_callback .s (
779
784
version_pk = self .version .pk ,
@@ -930,6 +935,7 @@ def sync_files(
930
935
search = False ,
931
936
pdf = False ,
932
937
epub = False ,
938
+ delete_unsynced_media = True
933
939
):
934
940
"""
935
941
Sync build artifacts to application instances.
@@ -941,40 +947,6 @@ def sync_files(
941
947
version = Version .objects .get_object_or_log (pk = version_pk )
942
948
if not version :
943
949
return
944
- if not pdf :
945
- remove_dirs ([
946
- version .project .get_production_media_path (
947
- type_ = 'pdf' ,
948
- version_slug = version .slug ,
949
- ),
950
- ])
951
-
952
- if getattr (storage , 'write_build_media' , False ):
953
- # Remove PDF from remote storage if it exists
954
- storage_path = version .project .get_storage_path (
955
- type_ = 'pdf' ,
956
- version_slug = version .slug ,
957
- )
958
- if storage .exists (storage_path ):
959
- log .info ('Removing %s from media storage' , storage_path )
960
- storage .delete (storage_path )
961
- if not epub :
962
- remove_dirs ([
963
- version .project .get_production_media_path (
964
- type_ = 'epub' ,
965
- version_slug = version .slug ,
966
- ),
967
- ])
968
-
969
- if getattr (storage , 'write_build_media' , False ):
970
- # Remove ePub from remote storage if it exists
971
- storage_path = version .project .get_storage_path (
972
- type_ = 'epub' ,
973
- version_slug = version .slug ,
974
- )
975
- if storage .exists (storage_path ):
976
- log .info ('Removing %s from media storage' , storage_path )
977
- storage .delete (storage_path )
978
950
979
951
# Sync files to the web servers
980
952
move_files (
@@ -986,6 +958,7 @@ def sync_files(
986
958
search = search ,
987
959
pdf = pdf ,
988
960
epub = epub ,
961
+ delete_unsynced_media = delete_unsynced_media ,
989
962
)
990
963
991
964
# Symlink project
@@ -1005,6 +978,7 @@ def move_files(
1005
978
search = False ,
1006
979
pdf = False ,
1007
980
epub = False ,
981
+ delete_unsynced_media = True ,
1008
982
):
1009
983
"""
1010
984
Task to move built documentation to web servers.
@@ -1021,10 +995,70 @@ def move_files(
1021
995
:type pdf: bool
1022
996
:param epub: Sync ePub files
1023
997
:type epub: bool
998
+ :param delete_unsynced_media: Whether to try and delete files.
999
+ :type delete_unsynced_media: bool
1024
1000
"""
1025
1001
version = Version .objects .get_object_or_log (pk = version_pk )
1026
1002
if not version :
1027
1003
return
1004
+
1005
+ # This is False if we have already synced media files to blob storage
1006
+ # We set `epub=False` for example so data doesn't get re-uploaded on each web,
1007
+ # so we need this to protect against deleting in those cases
1008
+ if delete_unsynced_media :
1009
+ if not pdf :
1010
+ remove_dirs ([
1011
+ version .project .get_production_media_path (
1012
+ type_ = 'pdf' ,
1013
+ version_slug = version .slug ,
1014
+ ),
1015
+ ])
1016
+
1017
+ if getattr (storage , 'write_build_media' , False ):
1018
+ # Remove PDF from remote storage if it exists
1019
+ storage_path = version .project .get_storage_path (
1020
+ type_ = 'pdf' ,
1021
+ version_slug = version .slug ,
1022
+ )
1023
+ if storage .exists (storage_path ):
1024
+ log .info ('Removing %s from media storage' , storage_path )
1025
+ storage .delete (storage_path )
1026
+ if not epub :
1027
+ remove_dirs ([
1028
+ version .project .get_production_media_path (
1029
+ type_ = 'epub' ,
1030
+ version_slug = version .slug ,
1031
+ ),
1032
+ ])
1033
+
1034
+ if getattr (storage , 'write_build_media' , False ):
1035
+ # Remove ePub from remote storage if it exists
1036
+ storage_path = version .project .get_storage_path (
1037
+ type_ = 'epub' ,
1038
+ version_slug = version .slug ,
1039
+ )
1040
+ if storage .exists (storage_path ):
1041
+ log .info ('Removing %s from media storage' , storage_path )
1042
+ storage .delete (storage_path )
1043
+
1044
+ if not localmedia :
1045
+ remove_dirs ([
1046
+ version .project .get_production_media_path (
1047
+ type_ = 'htmlzip' ,
1048
+ version_slug = version .slug ,
1049
+ ),
1050
+ ])
1051
+
1052
+ if getattr (storage , 'write_build_media' , False ):
1053
+ # Remove ePub from remote storage if it exists
1054
+ storage_path = version .project .get_storage_path (
1055
+ type_ = 'htmlzip' ,
1056
+ version_slug = version .slug ,
1057
+ )
1058
+ if storage .exists (storage_path ):
1059
+ log .info ('Removing %s from media storage' , storage_path )
1060
+ storage .delete (storage_path )
1061
+
1028
1062
log .debug (
1029
1063
LOG_TEMPLATE .format (
1030
1064
project = version .project .slug ,
0 commit comments