Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Path.GetTempPath for the GEA path.
  • Loading branch information
carlossanlop committed Jun 22, 2022
commit df9e81d6d0c0bd68adda4f3c4cf55a22fb039883
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,8 @@ private static string GenerateGlobalExtendedAttributeName(int globalExtendedAttr
{
Debug.Assert(globalExtendedAttributesEntryNumber >= 1);

Copy link
Member

@danmoseley danmoseley Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside - the code below reading TMPDIR then falling back to /tmp- why doesn't it just call Path.GetTempPath() that does the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I'll use Path.GetTempPath.

Here's why I wasn't using that:

The GNU tar manual specifies how the global extended attribute header name field obtains its value:

8.3.7.1 Controlling Extended Header Keywords

$TMPDIR/GlobalHead.%p.%n

[...] $TMPDIR stands for the value of the TMPDIR environment variable. If TMPDIR is not set, tar uses /tmp.

This description looks very similar to the remarks section of Path.GetTempPath:

Remarks

This method checks for the existence of environment variables in the following order and uses the first path found:

Linux

  1. The path specified by the TMPDIR environment variable. If the path is not specified in the TMPDIR environment variable, the default path /tmp/ is used.

Windows

  1. The path specified by the TMP environment variable.
  2. The path specified by the TEMP environment variable.
  3. The path specified by the USERPROFILE environment variable.
  4. The Windows directory.

So a couple of things need to be considered if we are to use Path.GetTempPath:

  • I don't see why any tool would be reading the GEA path, or having reading/writing behavior depend on it. The field isn't very interesting, unless the user cares about the process ID or the sequence number.
  • Keep in mind that none of the tar specs (at least the ones I read) specify what the expected behavior for Windows should be. Everything is Unix focused. If we format that string embedding Windows paths, I hope other tools don't break due to finding unexpected drive names or \ separators in that field. But go back to the previous point: I don't think any tool should make its behavior depend on this field.
  • If the Windows path ends up being larger than than 100 bytes, the sequence number and process ID would get truncated. Which is fine, I guess, because a couple of lines below, I re-generate the string by forcing the usage of /tmp.

string? tmpDir = Environment.GetEnvironmentVariable("TMPDIR");
if (string.IsNullOrWhiteSpace(tmpDir))
{
tmpDir = "/tmp";
}
else if (Path.EndsInDirectorySeparator(tmpDir))
string tmpDir = Path.GetTempPath();
if (Path.EndsInDirectorySeparator(tmpDir))
{
tmpDir = Path.TrimEndingDirectorySeparator(tmpDir);
}
Expand Down