The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - General (http://hintsforums.macworld.com/forumdisplay.php?f=16)
-   -   Need Help Deleting a file.... (http://hintsforums.macworld.com/showthread.php?t=58436)

hayne 07-22-2006 04:06 AM

One more (probably hopeless) thing you could try is to use 'unlink' instead of 'rm' to remove the file.
/bin/unlink is a hard link to /bin/rm but when the program is invoked as 'unlink', a simpler path through the source code is followed (since 'unlink' is less featureful).

hayne 07-22-2006 04:32 AM

Following up on my last suggestion, I wrote a C program that tries to use the 'unlink' system call to remove a file with the same name as the troublesome file of this thread. (see source code below)
When I run this program on my machine, it fails with "Invalid argument" even though there is no such file on my machine. I.e. the failure comes before the place where the file is even located. Probably not too surprising.

Here's the source code:
Code:

// This C program attempts to unlink (i.e. remove) a file with a specified name.
// It is intended for deletion of files with strange characters in their names.
// Cameron Hayne (macdev@hayne.net)  July 2006
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>

void printString(char *str)
{
    int len = strlen(str);
    int i;
    for (i = 0; i < len; i++)
    {
        if (isprint(str[i]))
        {
            printf("%c", str[i]);
        }
        else
        {
            printf(" 0x%2x ", (unsigned char)str[i]);
        }
    }
    printf("\n");
}

int main()
{
    // this is the filename from the following macosxhints thread:
    // http://forums.macosxhints.com/showthread.php?t=58436
    char filename[] = "6CED******D3-F485-11D8-A856-003.jpg";
    filename[4] = 0xef;
    filename[5] = 0xbf;
    filename[6] = 0xbf;
    filename[7] = 0xef;
    filename[8] = 0xbf;
    filename[9] = 0xbf;

    printf("Attempting to unlink file named:\n");
    printString(filename);
    if (unlink(filename) != 0)
    {
        printf("Errno: %d\n", errno);
        perror(NULL);
        return -1;
    }

    return 0;
}


voldenuit 07-22-2006 05:15 AM

Quote:

Originally Posted by jmeyeris
The problem is that ls -i | cat -v doesn't work. I get an invalid argument error.

So, ls | cat -v works, but ls -i | cat -v doesn't ?

Quote:

Originally Posted by jmeyeris
I did, however, try to find the inode # of the directory that contains my bad file and then use the tip #10 info to delete it.

How did you do that ?

Quote:

Originally Posted by jmeyeris
This file was created by imovie. After I finished with a project, there were some files in the trash.

Would you be able to reproduce the creation of such an undeletable jpg file ? That would be very helpful.

Apple will most likely deny that there is a problem in need of fixing, unless we can not only demonstrate the the file can't be deleted, but also that it is possible to create such a file. Without a realistic possibility for this to happen, they'll probably assign the bug the dreaded "not to be fixed" status.

The other set of files with similar problems seen in the thread hayne quoted came from an external disk used for filesharing. Even though it was never discussed, my hunch is they may have been written by a non-OS X machine (Linux for example), but that's just a wild guess.
If you have a Linux box around with FireWire and HFS+ support, you could try to put the troublesome Mac in Target mode and see if you can rm it from there.

TN 1150 hints:
"Non-Mac OS implementations of HFS Plus may choose to simply ignore the textEncoding field. In this case, the field must be treated as a reserved field." http://developer.apple.com/technotes/tn/tn1150.html
So there is some hope encoding problems are handled in a more relaxed way by such implementations.

Anyway, good luck and thanks, you brought up a very interesting problem, if that can be any consolation ;).


All times are GMT -5. The time now is 05:33 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.