View | Details | Raw Unified | Return to bug 307098
Collapse All | Expand All

(-)zypp/media/MediaCurl.cc (-6 / +42 lines)
Lines 1100-1105 Link Here
1100
      ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
1100
      ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
1101
    }
1101
    }
1102
1102
1103
    // set IFMODSINCE time condition (no download if not modified)
1104
    curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
1105
    curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, PathInfo(target).mtime());
1106
1103
    string destNew = target.asString() + ".new.zypp.XXXXXX";
1107
    string destNew = target.asString() + ".new.zypp.XXXXXX";
1104
    char *buf = ::strdup( destNew.c_str());
1108
    char *buf = ::strdup( destNew.c_str());
1105
    if( !buf)
1109
    if( !buf)
Lines 1299-1314 Link Here
1299
    }
1303
    }
1300
#endif // DETECT_DIR_INDEX
1304
#endif // DETECT_DIR_INDEX
1301
1305
1302
    if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
1306
    long httpReturnCode = 0;
1307
    CURLcode infoRet = curl_easy_getinfo(_curl,
1308
                                         CURLINFO_RESPONSE_CODE,
1309
                                         &httpReturnCode);
1310
    bool modified = true;
1311
    if (infoRet == CURLE_OK)
1303
    {
1312
    {
1304
      ERR << "Failed to chmod file " << destNew << endl;
1313
      DBG << "HTTP response: " + str::numstring(httpReturnCode);
1314
      if ( httpReturnCode == 304 ) // not modified
1315
      {
1316
        DBG << " Not modified.";
1317
        modified = false;
1318
      }
1319
      DBG << endl;
1305
    }
1320
    }
1306
    ::fclose( file );
1321
    else
1322
    {
1323
      WAR << "Could not get the reponse code." << endl;
1324
    }
1307
1325
1308
    if ( rename( destNew, dest ) != 0 ) {
1326
    if (modified || infoRet != CURLE_OK)
1309
      ERR << "Rename failed" << endl;
1327
    {
1310
      ZYPP_THROW(MediaWriteException(dest));
1328
      // apply umask
1329
      if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
1330
      {
1331
        ERR << "Failed to chmod file " << destNew << endl;
1332
      }
1333
      ::fclose( file );
1334
1335
      // move the temp file into dest
1336
      if ( rename( destNew, dest ) != 0 ) {
1337
        ERR << "Rename failed" << endl;
1338
        ZYPP_THROW(MediaWriteException(dest));
1339
      }
1311
    }
1340
    }
1341
    else
1342
    {
1343
      // close and remove the temp file
1344
      ::fclose( file );
1345
      filesystem::unlink( destNew );
1346
    }
1347
1312
    DBG << "done: " << PathInfo(dest) << endl;
1348
    DBG << "done: " << PathInfo(dest) << endl;
1313
}
1349
}
1314
1350

Return to bug 307098