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.

Diff revision 6 (Latest)

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
Revision 38656cb New Change
[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] 21 lines
[+20] [+] public File getFile() {
57
    create(0600);
60
    create(0600);
58
  }
61
  }
59

    
   
62

   
60
  /**
63
  /**
61
   * Create a named FIFO object with the specified fs permissions.
64
   * Create a named FIFO object with the specified fs permissions.
62
   * This depends on the 'mknod' system utility existing. (for example,
65
   * This depends on the 'mknod' or 'mkfifo' (Mac OS X) system utility
63
   * provided by Linux coreutils). This object will be deleted when
66
   * existing. (for example, provided by Linux coreutils). This object
64
   * the process exits.
67
   * will be deleted when the process exits.
65
   * @throws IOException on failure.
68
   * @throws IOException on failure.
66
   */
69
   */
67
  public void create(int permissions) throws IOException {
70
  public void create(int permissions) throws IOException {
68
    String filename = fifoFile.toString();
71
    String filename = fifoFile.toString();
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
    Shell.execCommand("mknod", "--mode=0" + modeStr, filename, "p");
77
    try {

    
   
78
      String output = Shell.execCommand("mknod", "--mode=0" + modeStr,

    
   
79
          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);

    
   
90
    }
75

    
   
91

   
76
    // Schedule the FIFO to be cleaned up when we exit.
92
    // Schedule the FIFO to be cleaned up when we exit.
77
    this.fifoFile.deleteOnExit();
93
    this.fifoFile.deleteOnExit();
78
  }
94
  }
79
}
95
}
80

    
   
96

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