Review Board 1.7.22


SQOOP-339 Use of non-portable mknod utility causes build problems on Mac OS X

Review Request #1938 - Created Sept. 16, 2011 and submitted

Joey Echeverria
SQOOP-339
Reviewers
Sqoop
sqoop-trunk
Replaced the use of mknod with mkfifo in NamedFifo to improve compatibility with Mac OS X.
No new tests as the functionality is covered by an existing unit test. I ran the existing unit test and it worked. I don't have a Mac to test on right now, so it might be good to run the unit tests on one before commit.

Changes between revision 2 and 6

1 2 3 4 5 6
1 2 3 4 5 6

  1. src/java/com/cloudera/sqoop/io/NamedFifo.java: Loading...
src/java/com/cloudera/sqoop/io/NamedFifo.java
Diff Revision 2 Diff Revision 6
[20] 19 lines
[+20]
20

    
   
20

   
21
import java.io.File;
21
import java.io.File;
22
import java.io.IOException;
22
import java.io.IOException;
23

    
   
23

   
24
import org.apache.hadoop.util.Shell;
24
import org.apache.hadoop.util.Shell;

    
   
25
import org.apache.log4j.Logger;
25

    
   
26

   
26
/**
27
/**
27
 * A named FIFO channel.
28
 * A named FIFO channel.
28
 */
29
 */
29
public class NamedFifo {
30
public class NamedFifo {
30

    
   
31

   

    
   
32
  private static final Logger LOG = Logger.getLogger(NamedFifo.class);

    
   
33

   
31
  private File fifoFile;
34
  private File fifoFile;
32

    
   
35

   
33
  /** Create a named FIFO object at the local fs path given by 'pathname'. */
36
  /** Create a named FIFO object at the local fs path given by 'pathname'. */
34
  public NamedFifo(String pathname) {
37
  public NamedFifo(String pathname) {
35
    this.fifoFile = new File(pathname);
38
    this.fifoFile = new File(pathname);
[+20] [20] 33 lines
[+20] [+] public void create(int permissions) throws IOException {
69

    
   
72

   
70
    // Format permissions as a mode string in base 8.
73
    // Format permissions as a mode string in base 8.
71
    String modeStr = Integer.toString(permissions, 8);
74
    String modeStr = Integer.toString(permissions, 8);
72

    
   
75

   
73
    // Create the FIFO itself.
76
    // Create the FIFO itself.
74
    if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
77
    try {
75
      Shell.execCommand("mkfifo", "-m", "0" + modeStr, filename);
78
      String output = Shell.execCommand("mknod", "--mode=0" + modeStr,
76
    } else {
79
          filename, "p");
77
      Shell.execCommand("mknod", "--mode=0" + modeStr, filename, "p");
80
      LOG.info("mknod output:\n"+output);

    
   
81
    } catch (IOException ex) {

    
   
82
      LOG.info("IO error running mknod: " + ex.getMessage());

    
   
83
      LOG.debug("IO error running mknod", ex);

    
   
84
    }

    
   
85
    if (!this.fifoFile.exists()) {

    
   
86
      LOG.info("mknod failed, falling back to mkfifo");

    
   
87
      String output = Shell.execCommand("mkfifo", "-m", "0" + modeStr,

    
   
88
          filename);

    
   
89
      LOG.info("mkfifo output:\n"+output);
78
    }
90
    }
79

    
   
91

   
80
    // Schedule the FIFO to be cleaned up when we exit.
92
    // Schedule the FIFO to be cleaned up when we exit.
81
    this.fifoFile.deleteOnExit();
93
    this.fifoFile.deleteOnExit();
82
  }
94
  }
83
}
95
}
84

    
   
96

   
  1. src/java/com/cloudera/sqoop/io/NamedFifo.java: Loading...