@@ -33,20 +33,24 @@ func Run(options *RunOptions) error {
3333 knownPaths ["/" ] = true
3434
3535 addKnownPath := func (path string ) {
36- path = filepath .Clean (path )
3736 if path [0 ] != '/' {
3837 panic ("bug: tried to add relative path to known paths" )
3938 }
39+ cleanPath := filepath .Clean (path )
40+ slashPath := cleanPath
41+ if path [len (path )- 1 ] == '/' && cleanPath != "/" {
42+ slashPath += "/"
43+ }
4044 for {
41- if _ , ok := knownPaths [path ]; ok {
45+ if _ , ok := knownPaths [slashPath ]; ok {
4246 break
4347 }
44- knownPaths [path ] = true
45- path = filepath .Dir (path )
46- if path == "/" {
48+ knownPaths [slashPath ] = true
49+ cleanPath = filepath .Dir (cleanPath )
50+ if cleanPath == "/" {
4751 break
4852 }
49- path += "/"
53+ slashPath = cleanPath + "/"
5054 }
5155 }
5256
@@ -84,6 +88,7 @@ func Run(options *RunOptions) error {
8488 }
8589 arch := archives [slice .Package ].Options ().Arch
8690 copyrightPath := "/usr/share/doc/" + slice .Package + "/copyright"
91+ addKnownPath (copyrightPath )
8792 hasCopyright := false
8893 for targetPath , pathInfo := range slice .Contents {
8994 if targetPath == "" {
@@ -92,7 +97,9 @@ func Run(options *RunOptions) error {
9297 if len (pathInfo .Arch ) > 0 && ! contains (pathInfo .Arch , arch ) {
9398 continue
9499 }
95- addKnownPath (targetPath )
100+ if pathInfo .Kind != setup .GlobPath {
101+ addKnownPath (targetPath )
102+ }
96103 pathInfos [targetPath ] = pathInfo
97104 if pathInfo .Kind == setup .CopyPath || pathInfo .Kind == setup .GlobPath {
98105 sourcePath := pathInfo .Info
@@ -225,10 +232,27 @@ func Run(options *RunOptions) error {
225232 return nil
226233 }
227234 checkRead := func (path string ) error {
235+ var err error
228236 if ! knownPaths [path ] {
229- return fmt .Errorf ("cannot read file which is not selected: %s" , path )
237+ // we assume that path is clean and ends with slash if it designates a directory
238+ if path [len (path )- 1 ] == '/' {
239+ if path == "/" {
240+ panic ("internal error: content root (\" /\" ) is not selected" )
241+ }
242+ if knownPaths [path [:len (path )- 1 ]] {
243+ err = fmt .Errorf ("content is not a directory: %s" , path [:len (path )- 1 ])
244+ } else {
245+ err = fmt .Errorf ("cannot list directory which is not selected: %s" , path )
246+ }
247+ } else {
248+ if knownPaths [path + "/" ] {
249+ err = fmt .Errorf ("content is not a file: %s" , path )
250+ } else {
251+ err = fmt .Errorf ("cannot read file which is not selected: %s" , path )
252+ }
253+ }
230254 }
231- return nil
255+ return err
232256 }
233257 content := & scripts.ContentValue {
234258 RootDir : targetDirAbs ,
0 commit comments