PDA

View Full Version : problem copying files and unmount drives



alejo
14th July 2009, 16:08
Hi every body, I am new in this forum (sorry for my english).. I need help with a problem very particular;

Sumarizing, the code do this:

mount USB device
copy file to usb
umount USB device

When I try to copy files to an USB device it's all ok, but when I try to umount the device I get the error " can't umount the device. resource is busy". Another interesting thing is, if I umount the device in another console, and do a new copy of same files are all ok. So I think the problem is in the mkpath instruction.. I probe everything (I guess) in relation with dirs.. I create with mkdir, I close the path to the USB device, etc... but I have the same error.




// the function save the file in path to /FSMOUNT_PENDRIVE_MOUNTPOINT/LOG_LOTE_DIR/loteName

bool save2Pen::copy2Pen( QString loteName, QString file, QString path )
{

mountPendrive(); // mount device

QDir dirPen(FSMOUNT_PENDRIVE_MOUNTPOINT); // for make destiny directory

QString path_base = LOG_LOTE_DIR;

path_base.append("/");
path_base.append(loteName);


if(!dirPen.mkpath(path_base)) // create the path
{
printf("ERROR: Can't create Directory\n");
}


/* conditioning the originFile and the destinyFile */

QString fileOrigin = path, fileDest = FSMOUNT_PENDRIVE_MOUNTPOINT;
fileOrigin.append("/");
fileOrigin.append(file);

fileDest.append(path_base);
fileDest.append("/");
fileDest.append(file);


if(!QFile::exists(fileDest)) // check file exists
{
if(!QFile::copy( fileOrigin, fileDest )) // copy file
{
QMessageBox msg(this);
msg.setText(tr("Error: can't copy file"));
msg.setIcon( QMessageBox::Critical );
msg.exec();
goto out;
}
}


out:
umountPendrive(); // here is the problem!! can't umount device


}

calhal
14th July 2009, 21:41
This really doesn't look like Qt specific problem.
Maybe you simply should do what that error message is trying to tell you? Can't you check if the device is busy before trying to unmount it?

alejo
14th July 2009, 21:54
Yes, the device still are busy. But I don't know why. maybe I need to close the files used for copy. But I'm used a static function QFile:copy().