Ejemplo n.º 1
0
S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask)
{
    S32 count = 0;
    std::string filename;
    std::string fullpath;
    S32 result;
    while (getNextFileInDir(dirname, mask, filename, FALSE))
    {
        if ((filename == ".") || (filename == ".."))
        {
            // skipping directory traversal filenames
            count++;
            continue;
        }
        fullpath = dirname;
        fullpath += getDirDelimiter();
        fullpath += filename;

        S32 retry_count = 0;
        while (retry_count < 5)
        {
            if (0 != LLFile::remove(fullpath))
            {
                result = errno;
                llwarns << "Problem removing " << fullpath << " - errorcode: "
                        << result << " attempt " << retry_count << llendl;
                ms_sleep(1000);
            }
            else
            {
                if (retry_count)
                {
                    llwarns << "Successfully removed " << fullpath << llendl;
                }
                break;
            }
            retry_count++;
        }
        count++;
    }
    return count;
}
Ejemplo n.º 2
0
const std::string LLDir::findFile(const std::string& filename, const std::vector<std::string> search_paths) const
{
	std::vector<std::string>::const_iterator search_path_iter;
	for (search_path_iter = search_paths.begin();
		search_path_iter != search_paths.end();
		++search_path_iter)
	{
		if (!search_path_iter->empty())
		{
			std::string filename_and_path = (*search_path_iter);
			if (!filename.empty())
			{
				filename_and_path += getDirDelimiter() + filename;
			}
			if (fileExists(filename_and_path))
			{
				return filename_and_path;
			}
		}
	}
	return "";
}
Ejemplo n.º 3
0
S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask)
{
	if (!fileExists(dirname)) return 0;

	S32 count = 0;
	std::string filename; 
	std::string fullpath;
	S32 result;

	// File masks starting with "/" will match nothing, so we consider them invalid.
	if (LLStringUtil::startsWith(mask, getDirDelimiter()))
	{
		llwarns << "Invalid file mask: " << mask << llendl;
		llassert(!"Invalid file mask");
	}

	LLDirIterator iter(dirname, mask);
	while (iter.next(filename))
	{
		fullpath = dirname;
		fullpath += getDirDelimiter();
		fullpath += filename;

		if(LLFile::isdir(fullpath))
		{
			// skipping directory traversal filenames
			count++;
			continue;
		}

		S32 retry_count = 0;
		while (retry_count < 5)
		{
			if (0 != LLFile::remove(fullpath))
			{
				retry_count++;
				result = errno;
				llwarns << "Problem removing " << fullpath << " - errorcode: "
						<< result << " attempt " << retry_count << llendl;

				if(retry_count >= 5)
				{
					llwarns << "Failed to remove " << fullpath << llendl ;
					return count ;
				}

				ms_sleep(100);
			}
			else
			{
				if (retry_count)
				{
					llwarns << "Successfully removed " << fullpath << llendl;
				}
				break;
			}			
		}
		count++;
	}
	return count;
}