3

I have a function that i'm running on my windows against case sensitive remote server (SMB). The function creates two files: "fileA", "FILEa". When i'm trying to unlink the file "fileA" both of my files disappear from the folder. Right after that i'm calling for unlink file "FILEa",and get error that the file does not exist.

My code:

void my_function(Path path)
{
    Path filename1 = path;
    filename1 + "_fileA";
    Path filename2 = path;
    filename2 +"_FILEa";

    close(open(filename1,  O_CREAT | O_EXCL, S_IREAD | S_IWRITE));
    try
    {
        close(open(filename2,  O_CREAT | O_EXCL, S_IREAD | S_IWRITE));
    }
    catch (Exception e)
    {
        unlink(filename1);
        return;
    }

    unlink(filename1);
    unlink(filename2);
}

On wireshark , after Client's unlink , the Client send SMB Find request to query the content of the folder and the server return FILEa in the list. wireshark capture

It seems that windows has internal caching that handles Opens and fileA and FILEa are mapped to the same entry.

Edit: View of my folder after creating the two files: ![folder with files

I'm using Windows and the code is in cpp. Somebody knows why is this happening to me? Or if there is other function beside unlink that could remove only the chosen file and not both of them? Thank you.

Eig
  • 31
  • 2
  • I think this is done by samba. – drescherjm Nov 16 '20 at 15:33
  • 1
    Can you run the first part of the code without unlink just to ensure both files are created. Can you list both files in File Explorer. If you can list both of them, try deleting only one. Refresh to see if both got deleted. – Tarik Nov 16 '20 at 15:39
  • I believe SMB is a case insensitive protocol, even though it is case retentive. – Eljay Nov 16 '20 at 16:17
  • There are settings in samba that allow different options for case sensitivity. Search for "NAME MANGLING" in https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html – drescherjm Nov 16 '20 at 16:22
  • If you are using windows only and no samba I believe @Eljay is correct. Although recent windows has gained the ability to have case sensitivity for NTFS not sure about SMB with windows as the server. https://www.howtogeek.com/354220/how-to-enable-case-sensitive-folders-on-windows-10/ – drescherjm Nov 16 '20 at 16:42
  • @drescherjm • NTFS has been case sensitive from the start. The Win32 API does not expose that case sensitive capability. The POSIX API did support case sensitive, but the POSIX API is no longer available (although now with WSL, I'm not sure if that is once again supported). – Eljay Nov 16 '20 at 17:14
  • @Tarik I can see that the two files are created, if I delete only one of them both of the files disappear. After waiting couple of minutes and refreshing the second file appear again. If I am unlinking a different file name 'temp' between the two files the function succeeded, after unlinking temp, FILEa appear and can be unlinked immediately. Because of that it seems like maybe a windows caching problem? – Eig Nov 17 '20 at 10:57
  • There is no problem with the SMB SERVER, when I unlinked the first file the server return the list of files and my second file was still in there. You can see that in the attached capture. – Eig Nov 17 '20 at 13:27
  • @drescherjm did you tested it? windows Client VS Samba as a Case sensitive Server? – Eliad Cohen Nov 19 '20 at 07:20
  • I have had experience over the years. However I have not played with these settings recently. – drescherjm Nov 19 '20 at 12:24

0 Answers0