Skip to content

Commit 1d1a398

Browse files
committed
Fix for File names w/ funny characters in them
1 parent 137da7b commit 1d1a398

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ protected Path getInitialWorkingDirectory() {
208208

209209
public Path fileToPath(File path) {
210210
Enumeration<String> all = volumes.keys();
211-
String rawPath = path.toURI().getRawPath();
211+
String rawPath = path.getAbsolutePath();
212+
212213
String volume = null;
213214
String root = null;
214215

@@ -223,8 +224,7 @@ public Path fileToPath(File path) {
223224

224225
if(default_volume.equalsIgnoreCase(volume))
225226
volume = "";
226-
227-
return new Path("glusterfs://" + volume + "/" + rawPath.substring(root.length()));
227+
return new Path("glusterfs://" + volume + "/" + rawPath.substring(root.length()));
228228
}
229229

230230
public boolean rename(Path src, Path dst) throws IOException {
@@ -292,8 +292,7 @@ public FileStatus[] listStatus(Path f) throws IOException {
292292
results[j] = getFileStatus(fileToPath(names[i]));
293293
j++;
294294
} catch (FileNotFoundException e) {
295-
// ignore the files not found since the dir list may have have changed
296-
// since the names[] list was generated.
295+
System.err.println("ignoring : " + names[i]);
297296
}
298297
}
299298
if (j == names.length) {
@@ -345,12 +344,15 @@ public BlockLocation[] getFileBlockLocations(FileStatus file,long start,long len
345344
File f=pathToFile(file.getPath());
346345
BlockLocation[] result=null;
347346

348-
result=attr.getPathInfo(f.getPath(), start, len);
349-
if(result==null){
350-
log.info("Problem getting destination host for file "+f.getPath());
351-
return null;
347+
try{
348+
result=attr.getPathInfo(f.getPath(), start, len);
349+
}
350+
catch(Throwable t){
351+
if(result==null){
352+
log.info("Problem getting destination host for file "+f.getPath());
353+
return null;
354+
}
352355
}
353-
354356
return result;
355357
}
356358

src/test/java/org/apache/hadoop/fs/test/unit/HcfsFileSystemTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@
3131
import static org.junit.Assert.assertTrue;
3232

3333
import java.io.IOException;
34+
import java.util.Iterator;
3435

36+
import org.apache.hadoop.conf.Configuration;
3537
import org.apache.hadoop.fs.FSDataInputStream;
3638
import org.apache.hadoop.fs.FSDataOutputStream;
3739
import org.apache.hadoop.fs.FileStatus;
3840
import org.apache.hadoop.fs.FileSystem;
41+
import org.apache.hadoop.fs.LocatedFileStatus;
3942
import org.apache.hadoop.fs.Path;
43+
import org.apache.hadoop.fs.RemoteIterator;
4044
import org.apache.hadoop.fs.permission.FsAction;
4145
import org.apache.hadoop.fs.permission.FsPermission;
4246
import org.apache.hadoop.fs.test.connector.HcfsTestConnectorFactory;
@@ -45,7 +49,6 @@
4549
import org.junit.AfterClass;
4650
import org.junit.Assert;
4751
import org.junit.BeforeClass;
48-
import org.junit.Ignore;
4952
import org.junit.Test;
5053

5154
/**
@@ -56,6 +59,26 @@ public class HcfsFileSystemTest{
5659

5760
static FileSystem fs ;
5861

62+
63+
/**
64+
* See MAPREDUCE-5902 for context on why this test is critical
65+
* for ecosystem interoperability.
66+
*/
67+
@org.junit.Test
68+
public void testEncodedPaths() throws Exception {
69+
//FileSystem fs2 = FileSystem.getLocal(new Configuration());
70+
FileSystem fs2 = fs;
71+
Path encodedFiles=new Path("/tmp/encodedTest"+System.currentTimeMillis());
72+
fs2.mkdirs(encodedFiles);
73+
fs2.create(new Path(encodedFiles,"a"));
74+
fs2.create(new Path(encodedFiles,"a%2"));
75+
fs2.create(new Path(encodedFiles,"a%2a"));
76+
fs2.create(new Path(encodedFiles,"a%3a"));
77+
fs2.create(new Path(encodedFiles,"a%4a"));
78+
Assert.assertEquals(5, fs2.listStatus(encodedFiles).length);
79+
fs2.delete(encodedFiles);
80+
}
81+
5982
@BeforeClass
6083
public static void setup() throws Exception {
6184
HcfsTestConnectorInterface connector = HcfsTestConnectorFactory.getHcfsTestConnector();

0 commit comments

Comments
 (0)