backend/logrotate/spacewalk-backend-tools | 1
java/code/src/com/redhat/rhn/frontend/action/channel/manage/EditChannelAction.java | 2
java/code/src/com/redhat/rhn/frontend/action/common/DownloadFile.java | 31 +++++++---
java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java | 20 ++----
4 files changed, 33 insertions(+), 21 deletions(-)
New commits:
commit 5226d5c49b68bb205e23c68dbfb53645f61e0442
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Wed Nov 27 16:51:56 2013 +0100
1010205 - fix displaying of reposync log on WebUI
diff --git a/backend/logrotate/spacewalk-backend-tools b/backend/logrotate/spacewalk-backend-tools
index 43011c1..4d90f06 100644
--- a/backend/logrotate/spacewalk-backend-tools
+++ b/backend/logrotate/spacewalk-backend-tools
@@ -16,6 +16,7 @@
rotate 5
copytruncate
compress
+ delaycompress
notifempty
missingok
size=10M
diff --git a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/EditChannelAction.java b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/EditChannelAction.java
index b1773f2..a75dc40 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/EditChannelAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/EditChannelAction.java
@@ -596,7 +596,7 @@ public class EditChannelAction extends RhnAction implements Listable {
c.getLastSynced());
}
request.setAttribute("last_sync", lastSync);
- if (ChannelManager.getLatestSyncLogFile(c) != null) {
+ if (!ChannelManager.getLatestSyncLogFiles(c).isEmpty()) {
request.setAttribute("log_url",
DownloadManager.getChannelSyncLogDownloadPath(c,
ctx.getLoggedInUser()));
diff --git a/java/code/src/com/redhat/rhn/frontend/action/common/DownloadFile.java b/java/code/src/com/redhat/rhn/frontend/action/common/DownloadFile.java
index 2cae11f..94e16e9 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/common/DownloadFile.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/common/DownloadFile.java
@@ -54,10 +54,10 @@ import org.apache.struts.actions.DownloadAction;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
+import java.io.RandomAccessFile;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
@@ -100,6 +100,8 @@ public class DownloadFile extends DownloadAction {
private static final String CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
private static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain";
private static final String CONTENT_TYPE_TEXT_XML = "text/xml";
+ private static final Long DOWNLOAD_REPO_LOG_LENGTH = 102400L;
+ private static final Long DOWNLOAD_REPO_LOG_MIN_LENGTH = 10L;
/** {@inheritDoc} */
@Override
@@ -445,14 +447,27 @@ public class DownloadFile extends DownloadAction {
else if (type.equals(DownloadManager.DOWNLOAD_TYPE_REPO_LOG)) {
Channel c = ChannelFactory.lookupById(fileId);
ChannelManager.verifyChannelAdmin(user, fileId);
- File file = new File(ChannelManager.getLatestSyncLogFile(c));
-
StringBuilder output = new StringBuilder();
- BufferedReader input = new BufferedReader(new FileReader(file));
- String line;
- while ((line = input.readLine()) != null) {
- output.append(line);
- output.append("\n");
+ for (String fileName : ChannelManager.getLatestSyncLogFiles(c)) {
+ RandomAccessFile file = new RandomAccessFile(fileName, "r");
+ long fileLength = file.length();
+ if (fileLength > DOWNLOAD_REPO_LOG_LENGTH) {
+ file.seek(fileLength - DOWNLOAD_REPO_LOG_LENGTH);
+ // throw away text till end of the actual line
+ file.readLine();
+ }
+ else {
+ file.seek(0);
+ }
+ String line;
+ while ((line = file.readLine()) != null) {
+ output.append(line);
+ output.append("\n");
+ }
+ file.close();
+ if (output.length() > DOWNLOAD_REPO_LOG_MIN_LENGTH) {
+ break;
+ }
}
setTextContentInfo(response, output.length());
diff --git a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
index d7af019..658f41f 100644
--- a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
+++ b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
@@ -2647,7 +2647,7 @@ public class ChannelManager extends BaseManager {
* @param c channel
* @return the string of the filename (fully qualified)
*/
- public static String getLatestSyncLogFile(Channel c) {
+ public static List<String> getLatestSyncLogFiles(Channel c) {
String logPath = Config.get().getString(ConfigDefaults.SPACEWALK_REPOSYNC_LOG_PATH,
"/var/log/rhn/reposync/");
@@ -2655,19 +2655,15 @@ public class ChannelManager extends BaseManager {
File dir = new File(logPath);
List<String> possibleList = new ArrayList<String>();
String[] dirList = dir.list();
- if (dirList == null) {
- return null; // the log directory does not exist
- }
- for (String file : dirList) {
- if (file.contains(c.getLabel())) {
- possibleList.add(file);
+ if (dirList != null) {
+ for (String file : dirList) {
+ if (file.startsWith(c.getLabel()) && !file.endsWith(".gz")) {
+ possibleList.add(logPath + file);
+ }
}
+ Collections.sort(possibleList);
}
- if (possibleList.isEmpty()) {
- return null;
- }
- Collections.sort(possibleList);
- return logPath + possibleList.get(possibleList.size() - 1);
+ return possibleList;
}