From 0944090a29060f7fcd39a7517b9a1840075c5281 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 20 May 2009 23:31:10 +0100
Subject: [PATCH] Allow hscan to save data for fully-spec'd URLs

In case we pass a fully-specified URL to hscan, currently it will use as
is and that means the directory in which we want to save the status
files changes from what we mean. This patch changes hscan to replace all
slashes in the cluster name with underscores when generating the output
filenames.
---
 hscan.1  | 4 +++-
 hscan.hs | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/hscan.1 b/hscan.1
index c4bec29c3..37086a0a6 100644
--- a/hscan.1
+++ b/hscan.1
@@ -23,7 +23,9 @@ tools.
 For each cluster, two files named \fIcluster\fB.instances\fR and
 \fIcluster\fB.nodes\fR will be generated holding the instance and node
 data. These files can then be used in \fBhbal\fR(1) or \fBhn1\fR(1)
-via the \fB-i\fR and \fB-n\fR options.
+via the \fB-i\fR and \fB-n\fR options. In case the cluster name
+contains slashes (as it can happen when the cluster is a
+fully-specified URL), these will be replaced with underscores.
 
 The one-line output for each cluster will show the following:
 .RS
diff --git a/hscan.hs b/hscan.hs
index 4ce9cc710..228998768 100644
--- a/hscan.hs
+++ b/hscan.hs
@@ -130,6 +130,11 @@ printCluster nl il ktn kti =
                  ccv
 
 
+-- | Replace slashes with underscore for saving to filesystem
+
+fixSlash :: String -> String
+fixSlash = map (\x -> if x == '/' then '_' else x)
+
 -- | Main function.
 main :: IO ()
 main = do
@@ -170,7 +175,7 @@ main = do
                                       putStr $ Cluster.printNodes ktn fix_nl
                              let ndata = serializeNodes nl csf ktn
                                  idata = serializeInstances il csf ktn kti
-                                 oname = odir </> name
+                                 oname = odir </> (fixSlash name)
                              writeFile (oname <.> "nodes") ndata
                              writeFile (oname <.> "instances") idata)
        ) clusters
-- 
GitLab