@@ -77,21 +77,25 @@ func MkdirAllAndChownNew(path string, mode os.FileMode, ids IDPair) error {
7777// GetRootUIDGID retrieves the remapped root uid/gid pair from the set of maps.
7878// If the maps are empty, then the root uid/gid will default to "real" 0/0
7979func GetRootUIDGID (uidMap , gidMap []IDMap ) (int , int , error ) {
80- uid , err := toHost (0 , uidMap )
80+ uid , err := RawToHost (0 , uidMap )
8181 if err != nil {
8282 return - 1 , - 1 , err
8383 }
84- gid , err := toHost (0 , gidMap )
84+ gid , err := RawToHost (0 , gidMap )
8585 if err != nil {
8686 return - 1 , - 1 , err
8787 }
8888 return uid , gid , nil
8989}
9090
91- // toContainer takes an id mapping, and uses it to translate a
92- // host ID to the remapped ID. If no map is provided, then the translation
93- // assumes a 1-to-1 mapping and returns the passed in id
94- func toContainer (hostID int , idMap []IDMap ) (int , error ) {
91+ // RawToContainer takes an id mapping, and uses it to translate a host ID to
92+ // the remapped ID. If no map is provided, then the translation assumes a
93+ // 1-to-1 mapping and returns the passed in id.
94+ //
95+ // If you wish to map a (uid,gid) combination you should use the corresponding
96+ // IDMappings methods, which ensure that you are mapping the correct ID against
97+ // the correct mapping.
98+ func RawToContainer (hostID int , idMap []IDMap ) (int , error ) {
9599 if idMap == nil {
96100 return hostID , nil
97101 }
@@ -104,10 +108,14 @@ func toContainer(hostID int, idMap []IDMap) (int, error) {
104108 return - 1 , fmt .Errorf ("Host ID %d cannot be mapped to a container ID" , hostID )
105109}
106110
107- // toHost takes an id mapping and a remapped ID, and translates the
108- // ID to the mapped host ID. If no map is provided, then the translation
109- // assumes a 1-to-1 mapping and returns the passed in id #
110- func toHost (contID int , idMap []IDMap ) (int , error ) {
111+ // RawToHost takes an id mapping and a remapped ID, and translates the ID to
112+ // the mapped host ID. If no map is provided, then the translation assumes a
113+ // 1-to-1 mapping and returns the passed in id.
114+ //
115+ // If you wish to map a (uid,gid) combination you should use the corresponding
116+ // IDMappings methods, which ensure that you are mapping the correct ID against
117+ // the correct mapping.
118+ func RawToHost (contID int , idMap []IDMap ) (int , error ) {
111119 if idMap == nil {
112120 return contID , nil
113121 }
@@ -178,25 +186,25 @@ func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
178186 target := i .RootPair ()
179187
180188 if pair .UID != target .UID {
181- target .UID , err = toHost (pair .UID , i .uids )
189+ target .UID , err = RawToHost (pair .UID , i .uids )
182190 if err != nil {
183191 return target , err
184192 }
185193 }
186194
187195 if pair .GID != target .GID {
188- target .GID , err = toHost (pair .GID , i .gids )
196+ target .GID , err = RawToHost (pair .GID , i .gids )
189197 }
190198 return target , err
191199}
192200
193201// ToContainer returns the container UID and GID for the host uid and gid
194202func (i * IDMappings ) ToContainer (pair IDPair ) (int , int , error ) {
195- uid , err := toContainer (pair .UID , i .uids )
203+ uid , err := RawToContainer (pair .UID , i .uids )
196204 if err != nil {
197205 return - 1 , - 1 , err
198206 }
199- gid , err := toContainer (pair .GID , i .gids )
207+ gid , err := RawToContainer (pair .GID , i .gids )
200208 return uid , gid , err
201209}
202210
0 commit comments