summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/DankMaterialShell/core/pkg/ipp/utils.go
blob: 62689a3b1396c119d7c21a287deb57b629849746 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package ipp

import (
	"fmt"
	"os"
	"path"
)

// ParseControlFile reads and decodes a cups control file into a response
func ParseControlFile(jobID int, spoolDirectory string) (*Response, error) {
	if spoolDirectory == "" {
		spoolDirectory = "/var/spool/cups"
	}

	controlFilePath := path.Join(spoolDirectory, fmt.Sprintf("c%d", jobID))

	if _, err := os.Stat(controlFilePath); err != nil {
		return nil, err
	}

	controlFile, err := os.Open(controlFilePath)
	if err != nil {
		return nil, err
	}
	defer controlFile.Close()

	return NewResponseDecoder(controlFile).Decode(nil)
}