简体   繁体   English

Cargo 如何准确检测文件更改?

[英]How exactly does Cargo detect file changes?

tl;dr: I want to know what cargo uses to determine whether or not a file has changed to debug a problem I've observed in my build system setup. tl; dr:我想知道cargo使用什么来确定文件是否已更改以调试我在构建系统设置中观察到的问题。

Description描述

I currently have lsyncd setup to mirror project files onto a remote linux machine where I compile code via ENVVARS_HERE=$my_values cargo build .我目前有lsyncd设置将项目文件镜像到远程 linux 机器上,我通过ENVVARS_HERE=$my_values cargo build编译代码。 lsyncd 's use of rsync w/ the archive flag unfortunately seems to not copy over whatever attribute it is that cargo uses to determine whether or not a file has been edited: lsyncd的是, lsyncd使用带有archive flagrsync似乎没有复制cargo用来确定文件是否已被编辑的任何属性:

I have a workspace set up:我设置了一个工作区:

workspace
+ crateA
  + ...
+ crateB
  + ...

where crateB depends on crateA .其中crateB取决于crateA Henceforth, 'remote machine' refers to the machine on which cargo is invoked, and 'local machine' refers to a machine editing the code that lsyncd then passes onto the 'remote machine'.此后,“远程机器”是指调用cargo的机器,“本地机器”是指编辑lsyncd然后传递到“远程机器”的代码的机器。 I will use 'recently' to refer to any time during which the dependencies of the action being described have not been changed relative to the state being described in a manner I am aware of.我将使用“最近”来指代所描述的动作的依赖关系没有以我所知道的方式相对于所描述的状态发生变化的任何时间。

Situation A情况A

Initial state:初始状态:

  • workspace has been copied from the local machine to the remote machine工作区已从本地机器复制到远程机器
  • lsyncd is not running on the local machine lsyncd没有在本地机器上运行
  • crateB has been compiled recently by cargo build on the remote machine crateB最近由远程机器上的cargo build编译

Perform:履行:

  • edit source file in crateB on the remote machine在远程机器上编辑crateB中的源文件
  • invoke cargo build on the remote machine在远程机器上调用cargo build

Result:结果:

  • crateB is recompiled by cargo on the remote machine crateB被远程机器上的cargo重新编译

Situation B情况B

Initial state:初始状态:

  • workspace has been copied from the local machine to the remote machine工作区已从本地机器复制到远程机器
  • lsyncd is running on the local machine (see notes below regarding configuration) lsyncd本地机器上运行(参见关于配置下面的注释)
  • crateB has been compiled recently by cargo build on the remote machine (see notes regarding timing relative to lsyncd 's operation modes) crateB最近由远程机器上的cargo build编译(请参阅有关与lsyncd操作模式相关的时间的注释)

Perform:履行:

  • edit crateB file on local machine在本地机器上编辑crateB文件
  • wait for synchronization to trigger and complete等待同步触发并完成
  • invoke cargo build on remote machine在远程机器上调用cargo build

Result:结果:

  • crateA compiles on the remote machine, followed by crateB crateA在远程机器上编译,然后是crateB

Notes笔记

  • lsyncd was run both with and without archive = true (which to the best of my knowledge sets rsync's archive flag to copy 'most' metadata, where 'most' appears to miss whatever it is that cargo cares about), with no observed change in the results. lsyncd在有和没有archive = true情况下运行(据我所知,这将 rsync 的archive标志设置为复制“最”元数据,其中“最”似乎错过了cargo关心的任何内容),没有观察到任何变化结果。
  • compilation for initial state where lsyncd was present was tested for the following cases with no observed changes in the results: compilation before lsyncd 's initial pass, and compilation after lsyncd 's initial pass针对以下情况测试了存在lsyncd初始状态的编译,结果中没有观察到任何变化: lsyncd的初始传递之前的编译,以及lsyncd的初始传递之后的编译
  • the target directory for lsyncd on the remote machine is on a tmpfs filesystem (if that makes some arcane difference)远程机器上lsyncd的目标目录位于tmpfs文件系统上(如果这会产生一些神秘的差异)

Question

I want a way to suss out what's going on here, both in this situation with lsyncd and in the future if/when I give up on lsyncd for some other approach that stumbles on a similar problem.我想要一种方法来弄清楚这里发生了什么,无论是在lsyncd这种情况下, lsyncd在未来,如果/当我放弃lsyncd而采用其他一些lsyncd发现类似问题的方法时。 Sources regarding cargo on eg SO reference the use of timestamps, but there are many kinds of timestamps and which timestamp they refer to is unclear.关于例如 SO 上的cargo来源引用了时间戳的使用,但是时间戳有很多种,它们指的是哪个时间戳尚不清楚。

What exactly does cargo check for when determining whether or not a file has changed?在确定文件是否已更改时, cargo究竟会检查什么?

So cargo uses fingerprints to track change metadata.因此,货物使用指纹来跟踪更改元数据。

Seems to me from reading the code that it's related to mtime , the modified time;在我看来,阅读与mtime相关的代码,修改时间; fingerprint::find_stale_file and paths::mtime_recursive . 指纹::find_stale_filepaths::mtime_recursive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM