001 /* 002 * Jpkg - Java library and tools for operating system package creation. 003 * 004 * Copyright (c) 2007 Three Rings Design, Inc. 005 * All rights reserved. 006 * 007 * Redistribution and use in source and binary forms, with or without 008 * modification, are permitted provided that the following conditions 009 * are met: 010 * 1. Redistributions of source code must retain the above copyright 011 * notice, this list of conditions and the following disclaimer. 012 * 2. Redistributions in binary form must reproduce the above copyright 013 * notice, this list of conditions and the following disclaimer in the 014 * documentation and/or other materials provided with the distribution. 015 * 3. Neither the name of the copyright owner nor the names of contributors 016 * may be used to endorse or promote products derived from this software 017 * without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 029 * POSSIBILITY OF SUCH DAMAGE. 030 */ 031 package com.threerings.jpkg; 032 033 034 /** 035 * Simple data class to contain permissions for paths used in a PermissionsMap. 036 */ 037 public class PathPermissions 038 { 039 /** 040 * Create a new permissions map which will be owned by the default user/group, e.g. root but 041 * have the supplied file mode set. 042 * @param mode the file permission mode, in represented octal, e.g. 0644. 043 * @param recursive whether to apply this permission recursively down the path. 044 */ 045 public PathPermissions (int mode, boolean recursive) 046 { 047 this(UnixStandardPermissions.ROOT_USER.getName(), UnixStandardPermissions.ROOT_GROUP.getName(), 048 mode, recursive); 049 } 050 051 /** 052 * Create a new permissions map with the given user and group owner. 053 * @param mode the file permission mode, in represented octal, e.g. 0644. 054 * @param recursive whether to apply this permission recursively down the path. 055 */ 056 public PathPermissions (String user, String group, int mode, boolean recursive) 057 { 058 _user = user; 059 _group = group; 060 _uid = UnixStandardPermissions.ROOT_USER.getId(); 061 _gid = UnixStandardPermissions.ROOT_GROUP.getId(); 062 _mode = mode; 063 _recursive = recursive; 064 } 065 066 /** 067 * Create a new permissions map with the given uid and gid owner. 068 * @param mode the file permission mode, represented in octal, e.g. 0644. 069 * @param recursive whether to apply this permission recursively down the path. 070 */ 071 public PathPermissions (int uid, int gid, int mode, boolean recursive) 072 { 073 _user = UnixStandardPermissions.ROOT_USER.getName(); 074 _group = UnixStandardPermissions.ROOT_GROUP.getName(); 075 _uid = uid; 076 _gid = gid; 077 _mode = mode; 078 _recursive = recursive; 079 } 080 081 /** 082 * The username to set as owner for this path. 083 */ 084 public String getUser () 085 { 086 return _user; 087 } 088 089 /** 090 * The groupname to set as owner for this path. 091 */ 092 public String getGroup () 093 { 094 return _group; 095 } 096 097 /** 098 * The user id to set as owner for this path. 099 */ 100 public int getUid () 101 { 102 return _uid; 103 } 104 105 /** 106 * The group id to set as owner for this path. 107 */ 108 public int getGid () 109 { 110 return _gid; 111 } 112 113 /** 114 * The file permission mode.. 115 */ 116 public int getMode () 117 { 118 return _mode; 119 } 120 121 /** 122 * Whether this permission map applies recursively down the path. 123 */ 124 public boolean isRecursive () 125 { 126 return _recursive; 127 } 128 129 @Override // from Object 130 public String toString () 131 { 132 final StringBuilder builder = new StringBuilder(); 133 builder.append("user=[").append(_user).append("], "); 134 builder.append("group=[").append(_group).append("], "); 135 builder.append("userId=[").append(_uid).append("], "); 136 builder.append("groupId=[").append(_gid).append("], "); 137 builder.append("mode=[").append(Integer.toOctalString(_mode)).append("], "); 138 builder.append("recursive=[").append(_recursive).append("]."); 139 return builder.toString(); 140 } 141 142 private final String _user; 143 private final String _group; 144 private final int _uid; 145 private final int _gid; 146 private final int _mode; 147 private final boolean _recursive; 148 }