简体   繁体   English

fs.statSync() 没有给出文件的实际出生时间 - NodeJs

[英]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 日志中,我得到了这个: 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.

相关问题 S3 putObject 没有使用 nodejs 将我的文件从 EFS 上传到 S3 Lambda - S3 putObject isn't uploading my file to S3 from EFS using nodejs Lambda gcloud alpha storage ls 找不到上传的文件 - gcloud alpha storage ls isn't finding uploaded file Python - 重置 BytesIO 以便不附加下一个文件 - Python - Reset BytesIO So Next File Isn't Appended s3 未上传文件并收到 SignatureDoesNotMatch 错误 - s3 isn't uploading file and getting error of SignatureDoesNotMatch 如何在 NodeJs 中使用 s3fs 从 S3 获取 object(图像)? - How to get an object (image) from S3 using s3fs in NodeJs? Next.js 未找到中间件模块:无法解析“fs” - Next.js middleware Module not found: Can't resolve 'fs' 为什么 Cloud Code 不尊重我的 cloudbuild.yaml 文件,但 gcloud beta 构建提交是? - Why isn't Cloud Code honoring my cloudbuild.yaml file but gcloud beta builds submit is? PubSub 未确认消息 - PubSub isn't acknowledging messages 找不到模块:无法解析 @google-cloud/storage 上的“fs” - Module not found: Can't resolve 'fs' on @google-cloud/storage imageFile 没有被识别? - imageFile isn't being recognized?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM