Beispiel #1
0
void deleteRecursive(const char* path) {
    string pathStr(path);
    if (pathStr[pathStr.size()-1] != '/') {
        pathStr += '/';
    }

    DIR* dir = opendir(path);
    if (!dir) {
        PLOG(ERROR) << "opendir " << path << " failed";
        return;
    }

    struct dirent* entry;
    while ((entry = readdir(dir))) {
        const char* name = entry->d_name;

        // ignore "." and ".."
        if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) {
            continue;
        }
        pathStr.append(name);
        if (entry->d_type == DT_DIR) {
            deleteRecursive(pathStr.c_str());
            rmdir(pathStr.c_str());
        } else {
            unlink(pathStr.c_str());
        }
    }
    closedir(dir);
}
void deleteRecursive(String path){
  File file = SD.open((char *)path.c_str());
  if(!file.isDirectory()){
    file.close();
    SD.remove((char *)path.c_str());
    return;
  }

  file.rewindDirectory();
  while(true) {
    File entry = file.openNextFile();
    if (!entry) break;
    String entryPath = path + "/" +entry.name();
    if(entry.isDirectory()){
      entry.close();
      deleteRecursive(entryPath);
    } else {
      entry.close();
      SD.remove((char *)entryPath.c_str());
    }
    yield();
  }

  SD.rmdir((char *)path.c_str());
  file.close();
}
Beispiel #3
0
/*
 *	Method:
 *	void BTree::deleteRecursive(Btree_Node* pNode)
 *
 *	Purpose: 
 *	A recursive method for freeing memory associated with nodes of BTree.
 *
 *	Input:
 *	node,	node whose memory will be freed, along with all descendants
 *
 *	Output:
 *	none
 */
void BTree::deleteRecursive(Btree_Node* pNode)
{
	if( NULL==pNode )
		return;

	for( int i=0; i<=pNode->nkeys; i++ )
		deleteRecursive( (pNode->child)[i] );
	delete pNode;
	return;
}
// DELETEメソッドに対応
void handleDelete(){
  if(server.args() == 0) return returnFail("BAD ARGS");
  String path = server.arg(0);
  if(path == "/" || !SD.exists((char *)path.c_str())) {
    returnFail("BAD PATH");
    return;
  }
  deleteRecursive(path);
  returnOK();
}
Beispiel #5
0
void test03(void)
{
    out_s("Fsfirst, Fsnext, Fsetdta, Fgetdta");
    createTestFiles();
    
    test0301();
    test0310();
    
    
    deleteRecursive("\\TESTDIR");
    out_s("");
}
static void deletePath(const char* path) {
    struct stat statbuf;
    if (stat(path, &statbuf) == 0) {
        if (S_ISDIR(statbuf.st_mode)) {
            deleteRecursive(path);
            rmdir(path);
        } else {
            unlink(path);
        }
    } else {
        LOGE("deletePath stat failed for %s: %s", path, strerror(errno));
    }
}
Beispiel #7
0
void deletePath(const char* path) {
    struct stat statbuf;
    if (stat(path, &statbuf) == 0) {
        if (S_ISDIR(statbuf.st_mode)) {
            deleteRecursive(path);
            rmdir(path);
        } else {
            unlink(path);
        }
    } else {
        PLOG(ERROR) << "deletePath stat failed for " << path;;
    }
}
static void deleteRecursive(const char* path) {
	char pathbuf[PATH_MAX];
	size_t pathLength = strlen(path);
	if (pathLength >= sizeof(pathbuf) - 1) {
		MTPE("path too long: %s\n", path);
	}
	strcpy(pathbuf, path);
	if (pathbuf[pathLength - 1] != '/') {
		pathbuf[pathLength++] = '/';
	}
	char* fileSpot = pathbuf + pathLength;
	int pathRemaining = sizeof(pathbuf) - pathLength - 1;

	DIR* dir = opendir(path);
	if (!dir) {
		MTPE("opendir %s failed: %s", path, strerror(errno));
		return;
	}

	struct dirent* entry;
	while ((entry = readdir(dir))) {
		const char* name = entry->d_name;

		// ignore "." and ".."
		if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) {
			continue;
		}

		int nameLength = strlen(name);
		if (nameLength > pathRemaining) {
			MTPE("path %s/%s too long\n", path, name);
			continue;
		}
		strcpy(fileSpot, name);

		int type = entry->d_type;
		struct stat st;
		if (lstat(pathbuf, &st)) {
			MTPE("Failed to lstat '%s'\n", pathbuf);
			continue;
		}
		if (st.st_mode & S_IFDIR) {
			deleteRecursive(pathbuf);
			rmdir(pathbuf);
		} else {
			unlink(pathbuf);
		}
	}
	closedir(dir);
}
Beispiel #9
0
void deleteRecursive( SquareWorldCube* node )
{
    if( node->children == 0 )
        return;

    deleteRecursive( node->children );
    deleteRecursive( node->children + 1 );
    deleteRecursive( node->children + 2 );
    deleteRecursive( node->children + 3 );
    deleteRecursive( node->children + 4 );
    deleteRecursive( node->children + 5 );
    deleteRecursive( node->children + 6 );
    deleteRecursive( node->children + 7 );

    free( node->children );
}
Beispiel #10
0
/*
 *	Method:
 *	BTree::~BTree(void)
 *
 *	Purpose: 
 *	Deletes BTree by freeing all the memory associated with the BTree nodes.
 *
 *	Input:
 *	none
 *
 *	Output:
 *	none
 */
BTree::~BTree(void)
{
	deleteRecursive(root);
	root = NULL;
}
Beispiel #11
0
SquareWorld::~SquareWorld( void )
{
    deleteRecursive( _cubes );
    free( _cubes );
}