现在,当我运行collectstatic时,它将所有文件从本地系统重新复制到S3,即使本地文件没有更改。查看collectstatic管理命令代码,我可以看到:
在方法delete_file中:
# The full path of the target file
if self.local:
full_path = self.storage.path(prefixed_path)
else:
full_path = None
# Skip the file if the source file is younger
# Avoid sub-second precision (see #14665, #19540)
if (target_last_modified.replace(microsecond=0) >= source_last_modified.replace(microsecond=0) and
full_path and not (self.symlink ^ os.path.islink(full_path))):
if prefixed_path not in self.unmodified_files:
self.unmodified_files.append(prefixed_path)
self.log("Skipping '%s' (not modified)" % path)
return False
在调试时,我看到即使target\u last\u修改了>=source_last_modified但full_path为None,这就是检查失败的原因,它最终会删除远程服务器上的文件。我不确定我做错了什么,或者我是否错过了一些设置,因为它正在重新上传文件。有趣的是,如果我删除上面代码中的额外检查,只需检查如下:
if (target_last_modified.replace(microsecond=0) >= source_last_modified.replace(microsecond=0)):
它工作得很好。
我也看到过类似的问题,但主要是由于S3和本地系统的时区不同。在我的例子中,我的本地时区和S3 bucket zone都是相同的。无论如何,上述黑客行为表明,问题不是由于时区差异造成的。