Browse Source

AMBARI-16116. Not able to edit Pig script tab. (Gaurav Nagar via dipayanb)

Dipayan Bhowmick 9 years ago
parent
commit
15a7ea3d5f

+ 10 - 4
contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileService.java

@@ -99,10 +99,7 @@ public class FileService extends BaseService {
         fillFakeFileObject(filePath, file, content);
       } else  {
 
-        if (!filePath.startsWith("/") && !filePath.startsWith(".")) {
-          filePath = "/" + filePath;  // some servers strip double slashes in URL
-        }
-
+        filePath = sanitizeFilePath(filePath);
         FilePaginator paginator = new FilePaginator(filePath, getSharedObjectsFactory().getHdfsApi());
 
         fillRealFileObject(filePath, page, file, paginator);
@@ -158,6 +155,7 @@ public class FileService extends BaseService {
   @Path("{filePath:.*}")
   public Response deleteFile(@PathParam("filePath") String filePath) throws IOException, InterruptedException {
     try {
+      filePath = sanitizeFilePath(filePath);
       LOG.debug("Deleting file " + filePath);
       if (getSharedObjectsFactory().getHdfsApi().delete(filePath, false)) {
         return Response.status(204).build();
@@ -179,6 +177,7 @@ public class FileService extends BaseService {
   public Response updateFile(FileResourceRequest request,
                              @PathParam("filePath") String filePath) throws IOException, InterruptedException {
     try {
+      filePath = sanitizeFilePath(filePath);
       LOG.debug("Rewriting file " + filePath);
       FSDataOutputStream output = getSharedObjectsFactory().getHdfsApi().create(filePath, true);
       output.writeBytes(request.file.getFileContent());
@@ -241,4 +240,11 @@ public class FileService extends BaseService {
   public static class FileResourceRequest {
     public FileResource file;
   }
+
+  private String sanitizeFilePath(String filePath){
+    if (!filePath.startsWith("/") && !filePath.startsWith(".")) {
+      filePath = "/" + filePath;  // some servers strip double slashes in URL
+    }
+    return filePath;
+  }
 }

+ 13 - 0
contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileService.java

@@ -69,6 +69,8 @@ public class FileService extends BaseService {
                           @QueryParam("page") Long page,
                           @QueryParam("action") String action) throws IOException, InterruptedException {
     try {
+
+      filePath = sanitizeFilePath(filePath);
       if (action != null && action.equals("ls")) {
         LOG.debug("List directory " + filePath);
         List<String> ls = new LinkedList<String>();
@@ -113,6 +115,9 @@ public class FileService extends BaseService {
   @Path("{filePath:.*}")
   public Response deleteFile(@PathParam("filePath") String filePath) throws IOException, InterruptedException {
     try {
+
+      filePath = sanitizeFilePath(filePath);
+
       LOG.debug("Deleting file " + filePath);
       if (getHdfsApi().delete(filePath, false)) {
         return Response.status(204).build();
@@ -134,6 +139,7 @@ public class FileService extends BaseService {
   public Response updateFile(FileResourceRequest request,
                              @PathParam("filePath") String filePath) throws IOException, InterruptedException {
     try {
+      filePath = sanitizeFilePath(filePath);
       LOG.debug("Rewriting file " + filePath);
       FSDataOutputStream output = getHdfsApi().create(filePath, true);
       output.writeBytes(request.file.getFileContent());
@@ -196,4 +202,11 @@ public class FileService extends BaseService {
   public static class FileResourceRequest {
     public FileResource file;
   }
+
+  private String sanitizeFilePath(String filePath){
+    if (!filePath.startsWith("/") && !filePath.startsWith(".")) {
+      filePath = "/" + filePath;  // some servers strip double slashes in URL
+    }
+    return filePath;
+  }
 }