def _create_dummy_file(self, base, size):
filepath = '{base}/{name}.dat'.format(base=base, name=self._gen_rand_str(5))
with open(filepath, 'wb') as f:
f.truncate(size)
# Change file creation and modification to random time
atime, mtime = self.get_rand_time_pair()
os.utime(filepath, times=(atime, mtime), follow_symlinks=False)
# Change st_birthtime on MacOS
if platform == 'darwin':
created_str = datetime.fromtimestamp(atime).strftime('%m/%d/%Y %H:%M:%S')
# subprocess.run with list arguments and shell=False behaves very strange
# and sets its st_birthtime to earlier than given timestamp very weirdly
command = 'SetFile -d "{0}" {1}'.format(created_str, filepath)
process = subprocess.Popen(command,
shell=True, close_fds=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
self._tasks_birthtime_flags.append(process)
self._total_size += size
return filepath, atime, mtime, os.stat(filepath).st_ctime
评论列表
文章目录