What is a .exe~ extension?

huangapple go评论89阅读模式
英文:

What is a .exe~ extension?

问题

我注意到go build现在会创建一个.exe文件和一个.exe~文件。

我已经搜索了一下,但没有找到相关信息。这种情况只发生在我使用的一个包的依赖中使用了一个奇怪的库之后。

我需要.exe~文件吗?我可以删除它吗?

英文:

I noticed that go build is now creating a .exe and a .exe~

I've googled and found nothing, this only started happening after one of the bazaar libraries was used as a dependency to a package I am using.

Do I need the .exe~ for anything? Can I delete it?

答案1

得分: 4

根据我的经验,在Windows上使用Go时,go build命令会创建一个.exe~的影子文件,原因如下:

  1. 之前你已经构建了运行时并创建了一个.exe文件。
  2. 你已经启动/执行了这个二进制文件。
  3. 之前的执行仍在运行中,或者Windows中发生了其他愚蠢的文件锁定。
  4. 当前二进制文件仍在使用中,你尝试再次执行go build命令。

在底层发生的情况是,当正在使用的.exe文件被go build命令执行时,它会将该文件重命名为.exe~,并将新的二进制文件放置在.exe以供下一次执行使用。

我一直对它如何在使用中的文件上执行这个操作感到着迷,因为其他所有Windows应用程序在过去的20多年中都会返回可怕的“文件正在使用”错误。

我最好的猜测是,当你执行一个Go二进制文件时,执行过程不会对文件进行锁定。因此,下一次构建可以简单地重命名正在使用的文件。

在我的测试中(2014年),新的.exe文件是最新版本,而.exe~文件是之前正在运行的版本。

我在这方面进行了大量的测试,因为我的使用情况是在重新编译时替换现有的二进制文件。

英文:

In my experience with Go on Windows, the go build command will create an .exe~ shadow file because of:

  1. You previously build the runtime and created an .exe.
  2. You already started/executed the binary.
  3. That previous execution is still running or some other stupid file lock by windows has occurred.
  4. You attempt to go build again, while the previous binary was still in use.

What happens under the hood is the go build will rename the existing executed .exe to .exe~ while it is in use, and will place the new binary at .exe for the next execution.

I have always been fascinated by how it does that to files in use, when 20+ years of all other Windows apps returns the dreaded "File In Use" error.

My best guess is that when you execute a go binary, the execution does not place a file lock on the file. So the next build can simply rename the in use one.

During my tests (2014) that new .exe was the latest version and the .exe~ was the previous version that was running.

I did a lot of testing around this as my use case purposely replaced the existing binary upon recompiling.

huangapple
  • 本文由 发表于 2016年9月18日 02:17:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/39550209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定