Skip to content

Commit 11e045d

Browse files
authored
Merge pull request #4159 from OpenShot/assets-folder-name-collision
Prevent Assets Folder Name Collision
2 parents 56b5de6 + a5b12ff commit 11e045d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/classes/assets.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"""
2727

2828
import os
29+
import shutil
2930
from classes import info
3031
from classes.logger import log
3132

@@ -37,17 +38,31 @@ def get_assets_path(file_path=None, create_paths=True):
3738
return info.USER_PATH
3839

3940
try:
40-
# Generate asset folder name, max 30 chars of filename + "_assets"
41+
# Generate asset folder name filename + "_assets"
4142
file_path = file_path
4243
asset_filename = os.path.splitext(os.path.basename(file_path))[0]
43-
asset_folder_name = asset_filename[:30] + "_assets"
44+
asset_folder_name = asset_filename[:248] + "_assets" #Windows max name size is 255. 248 = 255 - len("_assets")
4445
asset_path = os.path.join(os.path.dirname(file_path), asset_folder_name)
4546

47+
# Previous Assets File Name Convention.
48+
# We can remove the 30_char variables after 05/27/2022
49+
asset_folder_name_30_char = asset_filename[:30] + "_assets"
50+
asset_path_30_char = os.path.join(os.path.dirname(file_path), asset_folder_name_30_char)
51+
4652
# Create asset folder, if necessary
4753
if create_paths:
4854
if not os.path.exists(asset_path):
49-
os.mkdir(asset_path)
50-
log.info("Asset dir created as {}".format(asset_path))
55+
if os.path.exists(asset_path_30_char):
56+
#copy assets folder, if it follows the previous naming convention
57+
#must leave a copy for possible projects that shared the folder.
58+
try:
59+
shutil.copytree(asset_path_30_char, asset_path)
60+
log.info("Copying shortened asset folder. {}".format(asset_path))
61+
except:
62+
log.error("Could not make a copy of assets folder")
63+
else:
64+
os.mkdir(asset_path)
65+
log.info("Asset dir created as {}".format(asset_path))
5166
else:
5267
log.info("Using existing asset folder {}".format(asset_path))
5368

0 commit comments

Comments
 (0)