Ejemplo n.º 1
0
IO_METHOD(IoDirectory, createSubdirectory)
{
    /*doc Directory createSubdirectory(name)
    Create a subdirectory with the specified name.
    */

    IoState *state = IOSTATE;
    IoSymbol *subfolderName = IoMessage_locals_symbolArgAt_(m, locals, 0);
    IoObject *currentItem = IoDirectory_justAt(self, subfolderName);

    if (ISDIRECTORY(currentItem))
    {
        return currentItem;
    }

    if (ISFILE(currentItem))
    {
        IoState_error_(IOSTATE, m, "Attempt to create directory %s on top of existing file",
                       CSTRING(subfolderName));
    }
    else
    {
        IoSymbol *fullPath = IoDirectory_justFullPath(self, subfolderName);

        MKDIR(CSTRING(fullPath), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        return IoDirectory_newWithPath_(state, fullPath);
    }

    return IONIL(self);
}
Ejemplo n.º 2
0
IoObject *IoDirectory_itemForDirent_(IoDirectory *self, struct dirent *dp)
{
    IoSymbol *pathString;
    int isDir;
    UArray *path = IoSeq_rawUArray(DATA(self)->path);
    UArray *ba = UArray_clone(path);

    /*
    printf("IoDirectory_itemForDirent_ path = \"%s\" %i\n", p, path->itemSize);
    printf("IoDirectory_itemForDirent_ ba = \"%s\" %i\n", UArray_asCString(ba), ba->itemSize);
    */
    if (UArray_size(ba) && !IS_PATH_SEPERATOR(UArray_longAt_(ba, UArray_size(ba) - 1)))
    {
        UArray_appendCString_(ba, IO_PATH_SEPARATOR);
    }

    UArray_appendCString_(ba, dp->d_name);
    pathString = IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);

    isDir = isDirectory(dp, CSTRING(pathString));

    if (isDir)
    {
        return IoDirectory_newWithPath_(IOSTATE, pathString);
    }

    return IoFile_newWithPath_(IOSTATE, pathString);
}
Ejemplo n.º 3
0
IoObject *IoDirectory_justAt(IoDirectory *self, IoSymbol *name)
{
    IoState *state = IOSTATE;
    IoSymbol *fullPath = IoDirectory_justFullPath(self, name);
    struct stat st;

    if (stat(CSTRING(fullPath), &st) == -1)
    {
        return IONIL(self);
    }

    if ((st.st_mode & S_IFMT) == S_IFDIR)
    {
        return IoDirectory_newWithPath_(state, fullPath);
    }
    else
    {
        return IoFile_newWithPath_(state, fullPath);
    }

    return IONIL(self);
}
Ejemplo n.º 4
0
Archivo: IoUser.c Proyecto: Akiyah/io
IoObject *IoUser_homeDirectory(IoUser *self, IoObject *locals, IoMessage *m)
{
	TCHAR homePath[MAX_PATH];
	SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, homePath );
	return IoDirectory_newWithPath_(IOSTATE, IOSYMBOL(homePath));
}