Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Thu Jun 12, 2008 9:48 pm
Hi,
I've find this recursive function to delete a directory, but when I try to delete a big dir (PSP) , it was deleted all the MS!!
I've try to modify it but it's not perfect!
I think there are a basically solution, but I'haven't find it!
What's wrong in this function?
It's a possible bug of sceIoRmDir or sceIoDelete funct?
Code: Select all
void RmDir(char *dir)
{
SceIoDirent dirent;
int fd;
char fullname[512];
fd = sceIoDopen(dir);
memset(&dirent, 0, sizeof dirent);
while (sceIoDread(fd, &dirent) > 0)
{
sprintf(fullname, "%s/%s", dir, dirent.d_name);
if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
{
RmDir(fullname);
sceIoRmdir(fullname);
}
else
{
sceIoRemove(fullname);
}
}
sceIoDclose(fd);
sceIoRmdir(dir);
}
I think the problem is in the string fullname and in it's allocate ( not perfect english I think)
Last edited by
ne0h on Sat Jun 14, 2008 12:43 am, edited 2 times in total.
Insert_witty_name
Posts: 376 Joined: Wed May 10, 2006 11:31 pm
Post
by Insert_witty_name » Thu Jun 12, 2008 10:28 pm
What you call a big dir?
A directory with lots of files in it, or a directory with a really long name?
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Thu Jun 12, 2008 10:33 pm
Oh come on ! your wonderful function is not even slightly recursive. Is it so hard to think by yourself instead of gibbering ?
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Thu Jun 12, 2008 10:46 pm
This function is not my, I've searched and I've find this!
I call big dir a directory with a lot of dir and files
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Thu Jun 12, 2008 10:49 pm
This function is not my, I've searched and I've find this!
I call big dir a directory with a lot of dir and files
hilde, I haven't understand your post!
Explain your problem please!
Insert_witty_name
Posts: 376 Joined: Wed May 10, 2006 11:31 pm
Post
by Insert_witty_name » Thu Jun 12, 2008 11:13 pm
Hint: Your function is named RmDir().
Internally it's calling recursiveDelete()
Spot the difference.
That's what hlide meant by it not being recursive.
If you want to rename functions, ensure you rename all of them!
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 12:56 am
Excuse me,
I've writed bad the fuct ( the old func is named recursivedelete, but in my prog i've changed the name to RmDir)
However thanks but this is not the error
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Fri Jun 13, 2008 1:03 am
ne0h wrote: Excuse me,
I've writed bad the fuct ( the old func is named recursivedelete, but in my prog i've changed the name to RmDir)
However thanks but this is not the error
if so, why to remove a directory twice ? kinda fishy your excuse...
Code: Select all
void RmDir(char *dir)
{
SceIoDirent dirent;
int fd;
char fullname[512];
fd = sceIoDopen(dir);
memset(&dirent, 0, sizeof dirent);
while (sceIoDread(fd, &dirent) > 0)
{
sprintf(fullname, "%s/%s", dir, dirent.d_name);
if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
{
RmDir(fullname);
>>>sceIoRmdir(fullname);<<<
}
else
{
sceIoRemove(fullname);
}
}
sceIoDclose(fd);
>>>sceIoRmdir(dir);<<<
}
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 1:12 am
yes, it's a error but this is not my problem
Last edited by
ne0h on Fri Jun 13, 2008 2:49 am, edited 1 time in total.
J.F.
Posts: 2906 Joined: Sun Feb 22, 2004 11:41 am
Post
by J.F. » Fri Jun 13, 2008 1:21 am
You need to watch recursive functions - their greatest fault is the amount of stack space they consume. Look at ONE thing in the function:
Every recursion will consume that much stack space. If a dir has a thousand files, it will consume a thousand times the stack space. Make sure you have a BIG stack when using functions like this.
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 1:25 am
Ok, this is not the error but I've try to resolve it yet:
Code: Select all
int Rmdir(char *dir)
{
SceIoDirent dirent;
int fd;
fd = sceIoDopen(dir);
memset(&dirent, 0, sizeof dirent);
char *fullname=(char*)malloc(1);
free(fullname);
while (sceIoDread(fd, &dirent) > 0)
{
fullname=(char*)malloc(strlen(dir)+strlen(dirent.d_name)+1);
sprintf(fullname, "%s/%s", dir, dirent.d_name);
if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
{
Rmdir(fullname);
sceIoRmdir(fullname);
}
else
{
sceIoRemove(fullname);
}
}
sceIoDclose(fd);
sceIoRmdir(dir);
return 0;
}
I've writed it speedly, I think is not perfect! ( For memory use )
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Fri Jun 13, 2008 1:30 am
RmDir("ms0:/blabla") will call :
>RmDir("ms0:/blabla/bloblo");
>>sceIoRmdir("ms0:/blabla/bloblo"); // just after sceIoDclose(fd);
>sceIoRmdir("ms0:/blabla/bloblo"); // just after RmDir(fullname);
>sceIoRmdir("ms0:/blabla"); // just after sceIoDclose(fd);
Now, who's the idiot ?
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 1:32 am
What? Excuse me, maybe I'm a idiot but I haven't understand your post!
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Fri Jun 13, 2008 1:33 am
not a surprise
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 1:34 am
hlide, if I want delete a folder named "FOLDER", I think if I don't write the final sceIoRmDir the dir will be not deleted
J.F., I think the memory it's not the problem, because if I try yet to delete a big directory the PSP crash!
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Fri Jun 13, 2008 1:45 am
well i guess C is not your forte
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 1:48 am
bah
Last edited by
ne0h on Fri Jun 13, 2008 2:47 am, edited 2 times in total.
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:08 am
But what's wrong in my function?
I want know the bug if is possible!
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:10 am
Yeah, maybe I've resolved!
Code: Select all
int Rmdir(char *dir)
{
SceIoDirent dirent;
int fd;
fd = sceIoDopen(dir);
memset(&dirent, 0, sizeof dirent);
char *fullname=(char*)malloc(1);
free(fullname);
while (sceIoDread(fd, &dirent) > 0)
{
fullname=(char*)malloc(strlen(dir)+strlen(dirent.d_name)+1);
sprintf(fullname, "%s/%s", dir, dirent.d_name);
if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
{
Rmdir(fullname);
sceIoRmdir(fullname);
}
else
{
sceIoRemove(fullname);
--------->memset(&dirent, 0, sizeof dirent);
}
}
sceIoDclose(fd);
sceIoRmdir(dir);
return 0;
}
Last edited by
ne0h on Fri Jun 13, 2008 2:12 am, edited 1 time in total.
Question_dev
Posts: 88 Joined: Fri Aug 24, 2007 8:23 pm
Post
by Question_dev » Fri Jun 13, 2008 2:11 am
Compare the two.
If you can't find it by yourself, then you need to learn c.
Also, ever heard about google? "c delete dir"
Cu
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:13 am
... I've already resolved!
I've posted before read the other example!
Thanks, Question_dev!
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Fri Jun 13, 2008 2:22 am
"I've already resolved! " is your motto ? it sounds quite repetive to my ears... and unnecessary to say
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:24 am
I've writed this funct but this uses all the RAM!!!!
Why?
Code: Select all
int Rmdir(char *dir)
{
SceIoDirent dirent;
int fd;
fd = sceIoDopen(dir);
memset(&dirent, 0, sizeof dirent);
while (sceIoDread(fd, &dirent) > 0)
{
char fullname[strlen(dir)+strlen(dirent.d_name)+1];
sprintf(fullname, "%s/%s", dir, dirent.d_name);
if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
{
Rmdir(fullname);
sceIoRmdir(fullname);
}
else
{
sceIoRemove(fullname);
memset(&dirent, 0, sizeof dirent);
}
}
sceIoDclose(fd);
sceIoRmdir(dir);
return 0;
}
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:37 am
Thanks!...
Last edited by
ne0h on Fri Jun 13, 2008 2:43 am, edited 1 time in total.
Pirata Nervo
Posts: 409 Joined: Tue Oct 09, 2007 4:22 am
Post
by Pirata Nervo » Fri Jun 13, 2008 2:42 am
I lol'd at this thread.
@ne0h, make sure you learn some C coding before saying hlide is an idiot and does not know C and is more stupid than you. I believe hlide has a lot more C experience than you.
Also, it's not "I've writed", writed does not exists.
I'ts I've written or I wrote. (at least this is what I know from my english lol)
@Question Dev, maybe google will not be his best friend for coding lol and I think you are not the right person to say "SEARCH" as you were like him a few months ago.
Edit, don't bump your posts please. Wait for an answer if you even deserve one.
Upgrade your
PSP
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:46 am
bah...
I have understand what hlide intend to say yet...
Last edited by
ne0h on Fri Jun 13, 2008 2:50 am, edited 1 time in total.
Pirata Nervo
Posts: 409 Joined: Tue Oct 09, 2007 4:22 am
Post
by Pirata Nervo » Fri Jun 13, 2008 2:50 am
It's I haven't understood. (irregular verb)
he meant you were trying to delete the same directory after it was deleted.
Code: Select all
RmDir(fullname);
sceIoRmdir(fullname);
you run your RmDir function to delete the folder then you run sony's function to delete the folder, again.
Do you understand?
Upgrade your
PSP
ne0h
Posts: 386 Joined: Thu Feb 21, 2008 2:15 am
Post
by ne0h » Fri Jun 13, 2008 2:52 am
yes, yes, I have understand...
Pirata Nervo
Posts: 409 Joined: Tue Oct 09, 2007 4:22 am
Post
by Pirata Nervo » Fri Jun 13, 2008 2:52 am
ok, now how do you know your function is using all the ram?
Upgrade your
PSP