/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Give the user an overwrite warning if the target file exists const sal_Int32 openFlags = osl_File_OpenFlag_Write | osl_File_OpenFlag_Create; do
{
rc = osl_openFile(out.File.pData, &out.FileHandle, openFlags);
staticbool curl_run(std::u16string_view rURL, OutData& out, const OString& aProxyHost, sal_Int32 nProxyPort)
{ /* Need to investigate further whether it is necessary to call * curl_global_init or not - leave it for now (as the ftp UCB content * provider does as well).
*/
CURL * pCURL = curl_easy_init(); bool ret = false;
if( out.Offset > 0 )
{ // curl_off_t offset = nOffset; libcurl seems to be compiled with large // file support (and we not) ..
sal_Int64 offset = static_cast<sal_Int64>(out.Offset);
(void)curl_easy_setopt(pCURL, CURLOPT_RESUME_FROM_LARGE, offset);
}
CURLcode cc = curl_easy_perform(pCURL);
// treat zero byte downloads as errors if( nullptr == out.FileHandle )
openFile(out);
if( CURLE_OK == cc )
{
out.Handler->downloadFinished(out.File);
ret = true;
}
if ( CURLE_PARTIAL_FILE == cc )
{ // this sometimes happens, when a user throws away his user data, but has already // completed the download of an update.
curl_off_t nDownloadSize;
curl_easy_getinfo( pCURL, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &nDownloadSize ); if ( -1 == nDownloadSize )
{
out.Handler->downloadFinished(out.File);
ret = true;
}
}
// Avoid target file being removed elseif( (CURLE_ABORTED_BY_CALLBACK == cc) || out.StopCondition.check() )
ret = true;
// Only report errors when not stopped else
{
OString aMessage("Unknown error"_ostr);
// when rFile is empty, there is no remembered file name. If there is already a file with the // same name ask the user if she wants to resume a download or restart the download if ( aFile.isEmpty() )
{ // GetFileName()
OUString aURL( rURL ); // ensure no trailing '/'
sal_Int32 nLen = aURL.getLength(); while( (nLen > 0) && ('/' == aURL[ nLen-1 ]) )
aURL = aURL.copy( 0, --nLen );
// extract file name last '/'
sal_Int32 nIndex = aURL.lastIndexOf('/');
aFile = rDestinationDir + aURL.subView( nIndex );
if( osl_File_E_None == rc )
{ // Set file pointer to the end of the file on resume if( osl_File_E_None == osl_setFilePos(out.FileHandle, osl_Pos_End, 0) )
{
osl_getFilePos(out.FileHandle, &out.Offset);
}
} elseif( osl_File_E_NOENT == rc ) // file has been deleted meanwhile ..
out.File.clear();
}
// #i90930# Don't remove already downloaded bits, when curl_run reports an error // because later calls might be successful // if( ! ret ) // osl_removeFile(out.File.pData);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.