[英]fs.statSync() isn't giving actual BirthTime of the file - NodeJs
I am using fs (Node Module) to manage files.我正在使用 fs(节点模块)来管理文件。 I am getting the file's created time (BirthTime).
我正在获取文件的创建时间(出生时间)。 It is working absolutely fine when I run this app on my local machine.
当我在我的本地机器上运行这个应用程序时,它工作得非常好。 But when I try to implement it on EFS using NodeJs Lambda function then it gives 1970-01-01T00:00:00.000Z which is not the actual time of the file that I created.
但是当我尝试使用 NodeJs Lambda function 在 EFS 上实现它时,它会给出1970-01-01T00:00:00.000Z ,这不是我创建的文件的实际时间。
var efsDirectory = "/mnt/data/";
var filePath = path.join(efsDirectory, file);
console.log("This file is going to be executed :", file);
var response = fs.statSync(filePath);
let fileBirthTime = response.birthtime;
console.log("File path is : ", filePath);
After joining the path my filepath looks like this filepath = /mnt/data/172.807056.json which is the actual path of the file.加入路径后,我的文件路径看起来像这样filepath = /mnt/data/172.807056.json这是文件的实际路径。
In the Cloudwatch logs I am getting this:在 Cloudwatch 日志中,我得到了这个:
On the local machine, it is working fine and giving the actual file birthtime.在本地机器上,它工作正常并给出了实际的文件出生时间。 Can you tell me guys why I am getting this?
你能告诉我为什么我得到这个吗?
I posted the same question on the AWS repost, and an engineer responded to me with the following answer.我在 AWS 转发上发布了同样的问题,一位工程师用以下答案回复了我。 Pasting the same answer here, if someone is facing that problem too.
如果有人也面临这个问题,请在此处粘贴相同的答案。
You are getting this result with birthtime, as it is not supported on most NFS filesystems like EFS.您将通过 birthtime 获得此结果,因为大多数 NFS 文件系统(如 EFS)不支持它。 Even on Linux OSes it depends on the kernel and type of file system as to whether this field is supported.
即使在 Linux 操作系统上,是否支持此字段也取决于 kernel 和文件系统类型。 The default file system on Amazon Linux 2 on EBS doesn't return a value to birthtime.
EBS 上的 Amazon Linux 2 上的默认文件系统不会向 birthtime 返回值。 However with the latest Ubuntu image, it is supported.
但是,最新的 Ubuntu 图像支持它。 This is why you would be seeing a difference between running it locally and against EFS.
这就是为什么您会看到在本地运行它和针对 EFS 运行它之间的区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.