From 21a242c23e41621fe055ca51a6e2cc3e692f0158 Mon Sep 17 00:00:00 2001 From: dc-cheny <56348738+dc-cheny@users.noreply.github.com> Date: Fri, 19 Aug 2022 10:37:44 +0800 Subject: [PATCH] add case where the HOME directory does not have write permissions (#45229) * add case where the HOME directory does not have write permissions * add some notes --- python/paddle/dataset/common.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/paddle/dataset/common.py b/python/paddle/dataset/common.py index 5a10fe120ea..cebe77e5505 100644 --- a/python/paddle/dataset/common.py +++ b/python/paddle/dataset/common.py @@ -24,12 +24,25 @@ import sys import importlib import paddle.dataset import six.moves.cPickle as pickle +import tempfile import glob import paddle __all__ = [] HOME = os.path.expanduser('~') + +# If the default HOME dir does not support writing, we +# will create a temporary folder to store the cache files. +if not os.access(HOME, os.W_OK): + """ + gettempdir() return the name of the directory used for temporary files. + On Windows, the directories C:\TEMP, C:\TMP, \TEMP, and \TMP, in that order. + On all other platforms, the directories /tmp, /var/tmp, and /usr/tmp, in that order. + For more details, please refer to https://docs.python.org/3/library/tempfile.html + """ + HOME = tempfile.gettempdir() + DATA_HOME = os.path.join(HOME, '.cache', 'paddle', 'dataset') -- GitLab