Skip to content
Tcl Source Code View Ticket
Login

View Ticket

glob returns hidden files on win/macos

Closed / Fixed230474ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2001-01-30 17:14:11
On Unix, 'glob' only returns the hidden/invisible files (matching .*) if the pattern starts with '.' -- i.e. if the user specifically requested them.  On MacOS and Windows, in which invisibility is specified differently, hidden files are returned by default, even though the '-types hidden' option provides a mechanism to return them if they are desired.

For consistency the MacOS and Windows versions of glob should be updated to follow the Unix example.  Here's a patch for MacOS (tclMacFile.c should read):

int typeOk = 1;
if (types == NULL) {
    /* If invisible, don't return the file */
    if (pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible) {
typeOk = 0;
    }
} else {
    if (pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible) {
/* If invisible */
if ((types->perm == 0) || 
  !(types->perm & TCL_GLOB_PERM_HIDDEN)) {
    typeOk = 0;
}
    } else {
/* Visible */
if ((types->perm == 0) || 
  (types->perm & TCL_GLOB_PERM_HIDDEN)) {
    typeOk = 0;
}
    }
    if (typeOk == 1 && types->perm != 0) {
if (
    ((types->perm & TCL_GLOB_PERM_RONLY) &&
    !(pb.hFileInfo.ioFlAttrib & 1)) ||
    ((types->perm & TCL_GLOB_PERM_R) &&
    (TclpAccess(fname, R_OK) != 0)) ||
    ((types->perm & TCL_GLOB_PERM_W) &&
    (TclpAccess(fname, W_OK) != 0)) ||
    ((types->perm & TCL_GLOB_PERM_X) &&
    (TclpAccess(fname, X_OK) != 0))
    ) {
    typeOk = 0;
}
    }

and for Windows (tclWinFile.c):

int typeOk = 1;
attr = (*tclWinProcs->getFileAttributesProc)(nativeName);
if (types == NULL) {
    /* If invisible, don't return the file */
    if (attr & FILE_ATTRIBUTE_HIDDEN) {
typeOk = 0;
    }
} else {
    if (attr & FILE_ATTRIBUTE_HIDDEN) {
/* If invisible */
if ((types->perm == 0) || 
  !(types->perm & TCL_GLOB_PERM_HIDDEN)) {
    typeOk = 0;
}
    } else {
/* Visible */
if ((types->perm == 0) || 
  (types->perm & TCL_GLOB_PERM_HIDDEN)) {
    typeOk = 0;
}
    }
    if (typeOk == 1 && types->perm != 0) {
if (
    ((types->perm & TCL_GLOB_PERM_RONLY) &&
    !(attr & FILE_ATTRIBUTE_READONLY)) ||
    ((types->perm & TCL_GLOB_PERM_R) &&
    (TclpAccess(fname, R_OK) != 0)) ||
    ((types->perm & TCL_GLOB_PERM_W) &&
    (TclpAccess(fname, W_OK) != 0)) ||
    ((types->perm & TCL_GLOB_PERM_X) &&
    (TclpAccess(fname, X_OK) != 0))
    ) {
    typeOk = 0;
}
    }
nobodyplain2001-02-01 22:14:36
Vince adds: the above patch isn't quite right; I have a correct one now, but there is one issue which ought to be resolved.

On Unix hidden files are *defined* to be those beginning with '.', on MacOS hidden files are those which the OS has tagged as invisible.  Tcl agrees with both these.

However, on Windows hidden files are those the OS tags as invisible, but Tcl treats as invisible either those tagged by the OS or those beginning with '.' (at least according to the glob code).  This inconsistency needs fixing.  It is suggested that all special-casing of '.*' files be removed from the Windows version of glob, so that Tcl agrees with the native OS.
dgp Ticket [230474ffff]: 1 change [History diff]2001-04-14 02:18:38
vincentdarleyplain2001-08-01 18:08:28
Logged In: YES 
user_id=32170

One side-effect of TIP#17 is that this bug report of mine 
no longer applies.
Log in (anonymous is fine) to add a comment.