Skip to content

Commit

Permalink
Introduce the 'usertemp' filesystem type
Browse files Browse the repository at this point in the history
In the context of Git for Windows, the MSys2 root lives inside
%PROGRAMFILES% which is typically write-protected for mere mortals' user
accounts. In particular for /tmp/, this is a problem, because many
scripts assume that writing to /tmp/ is fair game.

MSys1 used to mount /tmp/ automatically, pointing to the current user's
temporary directory.

Let's recreate that functionality in a slightly different way: we now
interpret the filesystem type "usertemp" in the /etc/fstab file. To make
/tmp/ point to the temporary directory of the current user, as per the
%TMP% environment variable, just add this line to /etc/fstab:

	none /tmp usertemp binary,posix=0 0 0

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 16, 2015
1 parent 8b6b7e8 commit 2192264
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions winsup/cygwin/mount.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ mount_info::from_fstab_line (char *line, bool user)
unsigned mount_flags = MOUNT_SYSTEM | MOUNT_BINARY;
if (!strcmp (fs_type, "cygdrive"))
mount_flags |= MOUNT_NOPOSIX;
if (!strcmp (fs_type, "usertemp"))
mount_flags |= MOUNT_IMMUTABLE;
if (!fstab_read_flags (&c, mount_flags, false))
return true;
if (mount_flags & MOUNT_BIND)
Expand All @@ -1172,6 +1174,21 @@ mount_info::from_fstab_line (char *line, bool user)
slashify (posix_path, cygdrive, 1);
cygdrive_len = strlen (cygdrive);
}
else if (!strcmp (fs_type, "usertemp"))
{
WCHAR tmp[MAX_PATH];

if (GetEnvironmentVariableW (L"TEMP", tmp, sizeof(tmp)) && *tmp)
{
DWORD len;
char mb_tmp[len = sys_wcstombs (NULL, 0, tmp)];
sys_wcstombs (mb_tmp, len, tmp);

int res = mount_table->add_item (mb_tmp, posix_path, mount_flags);
if (res && get_errno () == EMFILE)
return false;
}
}
else
{
int res = mount_table->add_item (native_path, posix_path, mount_flags);
Expand Down

0 comments on commit 2192264

Please sign in to comment.